Page 1 of 1

How BLC thymeleaf works

Posted: Thu Jun 06, 2013 3:13 pm
by bharath0014
For eg: How the following expression @{${contentItem['targetUrl']}} in home.html executed.. I didnt find any contentItem model attribute or anything in controllers.. I am not sure from where value to contentItem.targetUrl is passed...

Similarly following expression ${navCategories} in nav.html... it finds the names, values of categories from blc_category table.. But how..? To which controller it is connecting, so that it calls service class to get the names, values of categories.. I didnt find any model attribute for navCategories..

can you please also tell me where the schema for blc:categories, blc:form etc are defined..

Re: How BLC thymeleaf works

Posted: Thu Jun 06, 2013 4:13 pm
by phillipuniverse
For eg: How the following expression @{${contentItem['targetUrl']}} in home.html executed.. I didnt find any contentItem model attribute or anything in controllers.. I am not sure from where value to contentItem.targetUrl is passed...


Take a look a couple of lines up from where you are looking (I bolded a line)

Code: Select all

        [b]<blc:content contentType="Homepage Banner Ad" />[/b]
        <div id="banners" th:if="${contentItem}">
            <a th:href="@{${contentItem['targetUrl']}}"><img th:src="@{${contentItem['imageUrl']}}" alt="Buy One Get One" /></a>       
        </div>


This executes the 'ContentProcessor' Thymeleaf Processor (which is analagous to a JSP tag). The javadocs for this processor are:

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 that processor populates the contentItem based on the parameters that are passed in.

Similarly following expression ${navCategories} in nav.html... it finds the names, values of categories from blc_category table.. But how..? To which controller it is connecting, so that it calls service class to get the names, values of categories.. I didnt find any model attribute for navCategories..


navCategories works the same way but with blc:categories.

We currently do not have DTD's defined for these tags which we recognize is not very ideal. There has been some work on an Eclipse plugin at https://github.com/thymeleaf/thymeleaf- ... pse-plugin which is almost ready for us to recommend and start writing our DTDs to validate against. The current hangup with that plugin is that it does not currently work with partials, but it looks like there were some commits today to address that (via setting a 'Thymeleaf Nature' on your project).

Re: How BLC thymeleaf works

Posted: Thu Jun 06, 2013 4:24 pm
by jfridye
In Broadleaf, we created a custom Thymeleaf dialect, which is a set of processors and related artifacts. An object that applies some logic to a DOM node is called a processor in Thymeleaf (think along the lines of a custom JSP tag).

Any tag you see in a Broadleaf template (.html) file which is prefixed with a 'blc:' namespace corresponds to a processor we wrote to provide custom utilities in our templates. The relevant worker class that pertains to each <blc:x/> tag can be found in the package org.broadleafcommerce.cms.web.processor.*

For instance, the worker class for <blc:categories ... /> is org.broadleafcommerce.cms.web.processor.CategoriesProcessor.
For <blc:content ... />, it's org.broadleafcommerce.cms.web.processor.ContentProcessor.

For more information on Thymeleaf dialects and processors, and more Thymeleaf basics, I highly recommend going through the Thymeleaf docs.

http://www.thymeleaf.org/doc/html/Using ... rd-dialect
http://www.thymeleaf.org/doc/html/Exten ... processors

Hope this helps.

Re: How BLC thymeleaf works

Posted: Sun Jun 09, 2013 11:54 pm
by bharath0014
Thanks for replies.... Now i got an idea.. I will dig deep to find out remaining :)