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

Not able to set meta fields coming from Java class

  • July 26, 2017
  • 13 replies
  • 3590 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

Feike_Visser1
Employee
July 26, 2017

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

Feike_Visser1
Employee
July 26, 2017

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

HTL Block Statements

New Participant
July 26, 2017

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.