Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to generate title into a class?

Avatar

Level 4

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

1 Accepted Solution

Avatar

Correct answer by
Level 10

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

View solution in original post

4 Replies

Avatar

Community Advisor

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

Avatar

Correct answer by
Level 10

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

Avatar

Level 4

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

Avatar

Community Advisor

Hi,

To format text/content apart from predefined HTL formats, you need to use Java or JS Use API.



Arun Patidar