Page 1 of 1

More complex StructuredContent

Posted: Wed Apr 24, 2013 4:35 am
by staleks
Hi,

I was following CMS tutorial, and managed to make RightHandSideBanner Ad work as BLC demo site works.

Now I have a more complex request. I need to have 4 images and 4 URL links as description of ONE banner space.

Client has an idea to use carousel to rotate those images.

I was thinking about solution to have one more complex BLC_FLD_GROUP with 8 BLC_FLD_DEF (2 fields per image representing image url and URL link that correlates that image)

Then I would have e.g. 'Carousel banner' as BLC_SC_FLD_TMPLT and ofcourse BLC_SC_FLDGRP_XREF, BLC_SC_TYPE, BLC_SC, BLC_SC_FLD and BLC_SC_FLD_MAP that follow that NEW field group definition.

In HTML, stuff stays the same, <blc:content contentType="Carousel Banner Ad" />
and then I would have something like:

Code: Select all

    <ul id="slider">
        <li>
            <a th:if="${contentItem}"  th:href="@{${contentItem['banner1_targetUrl']}}"><img th:src="@{${contentItem['banner1_imageUrl']}}" /></a>
        </li>
        <li>
            <a th:if="${contentItem}"  th:href="@{${contentItem['banner2_targetUrl']}}"><img th:src="@{${contentItem['banner2_imageUrl']}}" /></a>
        </li>
...


I think that this should work.

But I was thinking about more elegant solution.

E.g. Anyway all fields are same. They all have: imageURL and targetURL. But I have them four instead of just one. Is there maybe some solution to iterate through contentItem, e.g. JSTL c:forEach ???

Or I expect too much? :)

Thank You

Re: More complex StructuredContent

Posted: Wed Apr 24, 2013 9:13 am
by phillipuniverse
You're right, a more elegant solution does exist and you've come to the right place to find it :)

Rather than try to create multiple field groups, instead create a single field group, 2 field defs (representing image url and url link), a single fld template, and a SC_TYPE. Call the SC_TYPE something like 'Carousel Images'. In the admin, you can now create structured content keyed off of that 'Carousel Images' type: http://cl.ly/image/0o2D1o0e2y0R

After you've created some pieces of content for that particular content type, let's look at the Javadocs for the ContentProcessor (I know this is not easy to find; we're looking for a better solution for documenting these processors):

Code: Select all

/**
 * Processor used to display structured content that is maintained with the Broadleaf CMS.
 *
 * Usage based on the following attributes:<br>
 * <ul>
 *     <li>contentType (required) - specifies the content you are retrieving</li>
 *     <li>contentName - if included will retrieve only content that matches the name.   When no name is specified,
 *                       all matching content items of the passed in type are retrieved.</li>
 *     <li>maxResults - if specified limits the results to a specified number of items.   The content will be returned
 *                 according to priority.   If content items share the same priority, then they will be returned
 *                 randomly.  Consider the example with 5 matching items with priorities (1,2,3,3,3) respectively.  If
 *                 the count is set to 3.   Items 1 and 2 will ALWAYS be returned.   The third item returned will
 *                 randomy rotate through the 3rd, 4th, and 5th item.
 *     </li>
 *     <li>contentListVar - allows you to specify an alternate name for the list of content results.   By default,
 *                          the results are returned in the page attributed "contentList"</li>
 *     <li>contentItemVar - since a typical usage is to only return one item, the first item is returned in the
 *                          variable "contentItem".   This variable can be used to change the attribute name.</li>
 *     <li>numResultsVar  - variable holding the returns the number of results being returned to through the tag-lib.
 *                          defaults to "numResults".</li>
 * </ul>
 */


So this says that we can pass in the name of a content type and then get back all of the items in the list in a model variable called 'contentList'. So this would look exactly like the c:forEach you mentioned:

Code: Select all

<blc:content contentType="Carousel Images" />
<ul id="slider">
    <li th:each="item : ${contentList}">
        <a th:href="@{${item['targetUrl']}}"><img th:src="@{${item['imageUrl']}}" /></a>
    </li>
</ul>


This loops through all of the items in the list corresponding to the 'Carousel Images' content type and outputs the fields within each content item. For more on the th:each processor, check out the Thymeleaf docs.

Re: More complex StructuredContent

Posted: Thu Apr 25, 2013 6:07 am
by staleks
Great!

Thank you for your help. I've done it as suggested. Used 'Ad Template' as from demo, but defined one new BLC_SC_TMPLT. And defined 4 BLC_SC records but all of them of same Structured Content Template.

Figured it out that, <blc:content> will pick all items of same "template". So it will pick up 4 items and populate each <li> element with imageUrl and targetUrl.

So everythings works like a charm.

I have just one question more regarding this. I had to prepare everything for creating BLC_SC, I mean I have to create FLD_GROUP, FLD_DEF, BLC_SC_TEMPLATE. And only way I can do that is executing SQL updates.
Is this only way to do so?


Thank you once again for your help.

Re: More complex StructuredContent

Posted: Wed Jun 26, 2013 3:12 pm
by staleks
Actually, all you have looking at AdTemplate. Carousel is nothing more than 2, 3 images downloaded by your browser while page renders, just setting display:none or removing this css attribute, depending of position in carousel.

I am not sure where you are stalled, so please download DemoSite look how 'Right Hand Side' banner works. You will get idea what needs to be done. If you can't make it work, post here your problem. I will try to help you.

Thank you