my problem is following:
in this code
<header>
<h1 th:utext="${BLC_PAGE.pageFields[menu_name]}"></h1>
</header>
<blc:menu resultVar="menuItems" menuName="${BLC_PAGE.pageFields[menu_name]}" />
<ul th:if="${not #lists.isEmpty(menuItems)}">
<li th:each="menuItem : ${menuItems}">
<a th:href="#{${menuItem.url}}" th:class="${menuItemStat.first}? 'home'">
<span th:utext="${menuItem.label}"></span>
</a>
</li>
</ul>
the line <h1 th:utext="${BLC_PAGE.pageFields[menu_name]}"></h1> gets the name of actual menu. I need the menuName in this line <blc:menu resultVar="menuItems" menuName="${BLC_PAGE.pageFields[menu_name]}" /> to do the same thing, but "${BLC_PAGE.pageFields[menu_name]}" is not appropriate, as it is from thymeleaf tags library. Any idea how to get this this value in blc:menu tag?
In order to resolve the Thymeleaf expression ${BLC_PAGE.pageFields[menu_name]}, you will need to wrap it like so: th:attr="menuName=${BLC_PAGE.pageFields[menu_name]}". Because menuName is not a standard HTML attribute, you won't be able to simply add the Thymeleaf namespace to menuName (i.e., th:menuName), and, without the th: namespace, Thymeleaf doesn't know that it needs to resolve any expressions. The Thymeleaf attr attribute allows you to use non-standard HTML attributes with Thymeleaf. For more information on setting attribute values using Thymeleaf you can review their documentation.
Here are links to the Broadleaf and Thymeleaf documentation on Processors and Dialects:
Thymeleaf: http://www.thymeleaf.org/doc/tutorials/2.1/extendingthymeleaf.html#dialects-and-processors
Related
Anyone know that "th:for" is in Thymeleaf? I know it's a simple question, but I can't find the answer online, even in the Thymeleaf documentation.
It is the Thymeleaf attribute equivalent of the HTML for attribute used by <label> elements. For example:
<div class="preference">
<label for="cheese">Do you like cheese?</label>
<input type="checkbox" name="cheese" id="cheese">
</div>
It is listed in the Thymeleaf documentation section 5.2:
There are quite a lot of attributes like these, each of them targeting a specific HTML5 attribute...
It's no different from most other HTML attributes which have a Thymeleaf version - you can use it with a Thymeleaf expression. If you don't need a Thymeleaf expression, just use the plain for attribute instead.
I'm trying to replace a tag with a fragment of a template. After the inclusion, some part of the HTML code is removed
In my root page, I have
<p th:replace="mycomponent::firstFragment" th:with="myVar=#{'Hello'}"></p>
in my template I have
<p th:fragment="firstFragment" th:utext="#{someText}"><span th:utext="${myVar}"></span></p>
<p th:fragment="secondFragment" th:utext="#{someOtherText}"><span ></span>${otherVar}</p>
The outcome is only the p element of the fragment without the inside span. I've tried with th:inline="text" but maybe I used it in a wrong way
you can try th:include code. example .....
<span th:include="fragments/navbar::navbarPortion" th:remove="tag"/>
How can I replace "#panel-element-964921" to "#panel-element-${stateOne}" while having the value of "${stateOne}" to show up using Thymeleaf?
<div class="panel-heading">
<a class="panel-title" data-toggle="collapse"
data-parent="#panel-790692" href="#panel-element-964921" th:text="${stateOne}">State
Name</a>
</div>
Here it is th:href="|#panel-element-${stateOne}|"
To concatenate plain strings with server-side model attributes one of the easier approaches is to use the || symbol wherein we write the complete string with server-side variables embedded within ${varibale}. This is a common string template feature supported in quite a few programming languages (sadly not in Java)
Then any attributes to be processed by Thymeleaf need to be prepended by th:.
I am generating all menu link dynamically using Thymeleaf. I have written code which is working fine.
<ul>
<li th:each="menu : ${menus}">Home</span></li>
</ul>
My question is, how can I add a class (activeMenu) on li element if menu's value is equal to Home.
Usually you would insert this part in the element that you want to insert specific class, in your case span element:
th:class="${menu}=='Home' ? activeMenu"
or:
th:class="${menu}=='Home' ? activeMenu:''"
it should work like this:
<ul>
<li th:each="menu : ${menus}">th:text="${menu}">Home</span></li>
</ul>
I have not tried this specific condition, but it should work.
Hope this helps.
I have an object which I declared as "unique:true" and then I created a custom message in message.properties in grails. It appears correctly, but I don't know how to pass arguments to it. Is it even possible?
net.mypackage.MyObject.myField.unique = The Object {0} already belongs to the Object Group {1}.
I am aware that I can pass args via "g:message" but in this case I am rendering my errors via this snippet:
<g:hasErrors bean="${object}">
<ul class="errors no-margin" role="alert">
<g:eachError bean="${object}" var="error">
<li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message error="${error}"/></li>
</g:eachError>
</ul>
</g:hasErrors>
I can probably hack it like say do an if-else to determine if the error was a "unique constraint" error then pass the values, but other than that I don't have any idea. Most of the custom message examples I see on the internet are related to custom validators. I tried.. But I dont want to resort to that just yet... Any opinions on how to do this?
From the Grails documentation (http://grails.org/doc/latest/guide/i18n.html):
<g:message code="my.localized.content" args="${ ['Juan', 'lunes'] }" />