Page 1 of 1

Unable to understand Standard expression Syntex in demo site

Posted: Sun Feb 24, 2013 1:05 pm
by sunil
Hi

I go through a code syntex like this in demo site.

th:src="@{*{media['primary'].url}}" I know that it is a attribute of thymleaf template engine. What I want to ask is that I am unable to understand the syntex media['primary'], here what the barket '[]' meaning and 'primary' meaning?
I know I have to study this from thymleaf site. I studied at that site, but did not found any information.

Please explain above syntex and if possible provide me a link where i can study such expression in more details

My second question is which is also related to my above query is :-

where i found the custom attribute details of blc:price if there are another cutom attribute please tell me the details

Thanks

Re: Unable to understand Standard expression Syntex in demo site

Posted: Sun Feb 24, 2013 1:31 pm
by phillipuniverse
Thymeleaf documentation: http://www.thymeleaf.org/documentation. ... ation.html. "Using Thymeleaf" is where you should start.

For your particular example: th:src="@{*{media['primary'].url}}", let's start from the inside out.

  • media['primary'] - this treats the 'media' object like a map, and accesses the value that corresponds to the 'primary' key. The exact same as: ((Map)media).get('primary');
  • media['primary].url - after getting the value corresponding to the 'primary' key in the media map, get the 'url' property off of the returned object
  • *{media['primary'].url} - assume that the 'media' variable here corresponds to the context of an object defined by a 'th:object' attribute in a parent HTML element. Since I'll go ahead and assume that you are looking at one of the product HTML templates, somewhere in a parent element of this particular element, you will see something like "th:object=${product}". This means that all children element can do things like "th:text=*{productProperty}" instead of doing "th:text=${product.productProperty}"
  • @{*{media['primary'].url}} - the @ symbol will treat the returned value of the inner expression and treat that like a context-sensitive URL. So if *{media['primary'].url} returns something like "/path/to/image", but the web application is deployed to the 'store' context, the @ sign will rewrite the url to "/store/path/to/image".

If you take a look at the link to the Thymeleaf docs it has examples for all of these types of expressions. That should be your go-to reference.

For blc:price, take a look at the Java class PriceTextDisplayProcessor. There is only a single parameter to blc:price: a Money object.a