Not able add multiple Parsys using model | Community
Skip to main content
sesmic
March 3, 2024
Solved

Not able add multiple Parsys using model

  • March 3, 2024
  • 2 replies
  • 1694 views

Hi All,

I'm working on a component which will add multiple parsys, via Sling Model. The parsys isn't generating but any html apart from that is working as expected.

Java

 

@586265 private Integer pNumber; //input public String getPContent() { StringBuilder contentBuilder = new StringBuilder(); for (int i = 1; i <= pNumber; i++) { contentBuilder.append("<div data-sly-resource=\"${'parsys").append(i).append("' @ resourceType='wcm/foundation/components/parsys'}\"></div>"); } return contentBuilder.toString(); }

 

 

HTML

 

 

<div data-sly-use.model="com.example.models.componentImpl"> ${model.pContent @ context='unsafe'} </div>

 

 

Output when parsys is used(context = unsafe)

Thus, please advice me as what I'm doing wrong or I missed something & help me to achieve desired result.

Thanks,

sesmic

 

 

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 Imran__Khan

Please try below working and tested one, copy paste same code and try:

 

<sly data-sly-list.child="${modelName.parsysList}"> <div data-sly-resource="${ child @ resourceType='wcm/foundation/components/parsys'}"></div> </br> </sly>public List<String> getParsysList() { parsysList = new ArrayList<>(); for (int i = 1; i <= numberOfItems; i++) { parsysList.add("parsys-"+i); } return parsysList; }


There is some CSS issue in my local, though it worked and I can see multiple parsys.

 

 

2 replies

Imran__Khan
Community Advisor
Community Advisor
March 3, 2024

@sesmic  In below code data-sly-resource value parsys needs to be a dynamic variable like parsys, parsys-1, parsys-2, parsys-3. unique value for all parsys

 

StringBuilder htmlBuilder = new StringBuilder(); for (int i = 1; i <= numberOfItems; i++) { //htmlBuilder.append("<div style=\"background-color:yellow;\">Item ").append(i).append("</div>"); htmlBuilder.append("<div data-sly-resource='parsys"+i+"'"+" @ resourceType='wcm/foundation/components/parsys'></div>"); } return htmlBuilder.toString();

 

 

${model.htmlContent @ context='html'}

 

 

If Not working, please try below working one:

<sly data-sly-list.child="${modelName.parsysList}"> <div data-sly-resource="${ child @ resourceType='wcm/foundation/components/parsys'}"></div> </br> </sly>public List<String> getParsysList() { parsysList = new ArrayList<>(); for (int i = 1; i <= numberOfItems; i++) { parsysList.add("parsys-"+i); } return parsysList; }
sesmic
sesmicAuthor
March 3, 2024

Hi @imran__khan,

Thanks for the reply. I have also tried the approach you suggested. But still result is same. I have shared the snippets in my post as well. Anything apart from parsys or any resource is generating.

Imran__Khan
Community Advisor
Imran__KhanCommunity AdvisorAccepted solution
Community Advisor
March 3, 2024

Please try below working and tested one, copy paste same code and try:

 

<sly data-sly-list.child="${modelName.parsysList}"> <div data-sly-resource="${ child @ resourceType='wcm/foundation/components/parsys'}"></div> </br> </sly>public List<String> getParsysList() { parsysList = new ArrayList<>(); for (int i = 1; i <= numberOfItems; i++) { parsysList.add("parsys-"+i); } return parsysList; }


There is some CSS issue in my local, though it worked and I can see multiple parsys.

 

 

arunpatidar
Community Advisor
Community Advisor
March 4, 2024