Hello,
I want to generate a title into a class. Example:
<div data-sly-list="${contents.sections}">
<p>${item.sectionTitle}</p>
<p>${item.sectionContent}</p>
<div class="${item.subSectionTitle}" data-sly-list="${item.subSectionField}">
<p>${item.subSectionTitle}</p>
<p>${item.subSectionContent}</p>
</div>
</div>
The class as "${item.subSectionTitle}" but if the subSectionTitle have a space, I want to replace the "space" with the "-".
Example: subSectionTitle = Sub section title , the class will be class="sub-section-title" or the class="sub"
How to do that?
Thank you so much,
Bien
Solved! Go to Solution.
Views
Replies
Total Likes
When performing tasks like this - you should use Java. You can either use Sling Models or WCMUsePojo when working with HTL.
See this article if you are not familiar with Sling Models and HTL.
Building Experience Manager Components using Granite/Coral Resource Types
Views
Replies
Total Likes
HI,
We can have this amends done at Sling model level and not at HTL.
Add an instance variable in Bean Class say, subSectionTitleClass and in Sling Model Class, value for the same will be set as
"subSectionTitle -> to lowercase and introduce '-' when it gets to see space" and use this variable for "class" attribute in HTL
Views
Replies
Total Likes
When performing tasks like this - you should use Java. You can either use Sling Models or WCMUsePojo when working with HTL.
See this article if you are not familiar with Sling Models and HTL.
Building Experience Manager Components using Granite/Coral Resource Types
Views
Replies
Total Likes
Thank you for your help,
However, I can't generate the title into the class with sightly. Could you help me how to do that?
<div data-sly-list="${contents.sections}">
<p>${item.sectionTitle}</p>
<p>${item.sectionContent}</p>
<div class="${item.subSectionTitle}" data-sly-list="${item.subSectionField}">
<p>${item.subSectionTitle}</p>
<p>${item.subSectionContent}</p>
</div>
</div>
The class as "${item.subSectionTitle}" but if the subSectionTitle have a space, I want to replace the "space" with the "-".
Example: subSectionTitle = Sub section title , the class will be class="sub-section-title" or the class="sub-section"
Thank you so much,
BienHV
Views
Replies
Total Likes
Hi,
To format text/content apart from predefined HTL formats, you need to use Java or JS Use API.
Views
Replies
Total Likes
Views
Likes
Replies