Not able to set meta fields coming from Java class | Community
Skip to main content
Level 2
Jul 26, 2017 5:22 AM UTC
Solved

Not able to set meta fields coming from Java class

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.
Feike_Visser1
Feike_Visser1Accepted solution
Employee
Jul 26, 2017 7:20 PM UTC

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

Feike_Visser1
Employee
Jul 26, 2017 8:03 AM UTC

Also for the attributes, you can use data-sly-attribute, and pass in a Map with the attributes.

Translate
Feike_Visser1
Employee
Jul 26, 2017 7:58 AM UTC

Can try first with data-sly-element to set the element name.

HTL Block Statements

Translate
Level 4
Jul 26, 2017 7:41 AM UTC

seems like value of "metafield.value1" is "TagName1" and "metafield.value2" is "TagValue1".

If you want to get four different properties in single tag, you can create a POJO class containing these properties as variable and their getter, setter. Create a List of type this class(e.g. metaArray) in your WCMUse pojo set the properties and return it.

OR, if only one meta tag is required you can simply  set the values in four different variables in WCMUse pojo and fetch them in your html.

Translate