Not able to set meta fields coming from Java class | Community
Skip to main content
Level 2
July 26, 2017
Solved

Not able to set meta fields coming from Java class

  • July 26, 2017
  • 13 replies
  • 3607 views

Hi,

I am getting five values from my view helper(class extending WCMUse), these fields are meta, property1, property2, value1, value2 . My purpose is to set these values in metatag like: <meta  property1=value1  property2=value2 /> .Code doing this in Sightly component is:

<ul data-sly-list.metafield="${metaBean.metaArray}">

   <${metafield.meta}  ${metafield.property1}=${metafield.value1} ${metafield.property2}=${metafield.value2} />

</ul>

But while doing so it is getting set as

<${metafield.meta} ${metafield.property1}="TagName1" ${metafield.property2}="TagValue1"/>

Any help on how can i set it properly ?

Regards,

Surendra

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 Feike_Visser1

I found the way to do it:

<element data-sly-use.meta="com.adobe.examples.htl.core.attributes.DynamicAttributes" data-sly-element="${meta.elementName @ context='unsafe'}" data-sly-attribute="${meta.attributes}"></element>

full example here htl-examples/DynamicAttributes.java at master · heervisscher/htl-examples · GitHub

13 replies

susheel
Level 5
July 26, 2017

As you have everything in metafield.

You might try to create a list of maps, where metafield.meta is the key.

and value is another map object which contains your attributes.

Something like below roughly.

Map<String,String> attributes = new HashMap<>();

map.put("property1","value1");

map.put("property2","value2");

list.add(metaelement,attributes);

<sly data-sly-list.metafield="${metaBean.list}">

    <sly data-sly-element="${key @context='unsafe'}" data-sly-attribute="${metafield[key]}"></sly>

</sly>

Feike_Visser1
Adobe Employee
Feike_Visser1Adobe EmployeeAccepted solution
Adobe Employee
July 26, 2017

I found the way to do it:

<element data-sly-use.meta="com.adobe.examples.htl.core.attributes.DynamicAttributes" data-sly-element="${meta.elementName @ context='unsafe'}" data-sly-attribute="${meta.attributes}"></element>

full example here htl-examples/DynamicAttributes.java at master · heervisscher/htl-examples · GitHub

Level 2
July 27, 2017

It worked for me too

Thanks a ton !!