How to generate title into a class? | Community
Skip to main content
bhoang
Level 4
April 11, 2018
Solved

How to generate title into a class?

  • April 11, 2018
  • 4 replies
  • 2097 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

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

4 replies

Vijayalakshmi_S
Level 10
April 11, 2018

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

smacdonald2008
smacdonald2008Accepted solution
Level 10
April 11, 2018

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

bhoang
bhoangAuthor
Level 4
September 27, 2018

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

arunpatidar
Community Advisor
Community Advisor
September 27, 2018

Hi,

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

Arun Patidar