Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

Output HTML attribute name with HTL

Avatar

Level 3

If I want to output the attribute name via HTL, how do I go about doing this?

For example I want to be able to specify the meta tag as either <meta name=.. or <meta property=....

When I try this...

<meta ${metadata.metaTypeName}="${metadata.metaTypeNameValue}" content="${metadata.metaContentValue}" />

It renders in the HTML source as...

<meta ${metadata.metaTypeName}="metaTypeNameValue1" content="contentValue1"/>

The second two properties render fine, but the first one isn't getting evaluated.  Any thoughts?

1 Accepted Solution

Avatar

Correct answer by
Employee

You can pass in a Map to data-sly-attribute, that should do the trick.

To set multiple attributes, pass a map object hold key-value pairs corresponding to the attributes and their values. For example, assuming,

attrMap = {

    title: "myTitle",

    class: "myClass",

    id: "myId"

}

Then,

<div data-sly-attribute="${attrMap}"></div>

View solution in original post

5 Replies

Avatar

Level 3

Yes, I'm referencing a valid object.  It seems like it might have something to do with updating an attribute name, as the other attribute values are working fine.  Let me know if you have any other thoughts.

Avatar

Correct answer by
Employee

You can pass in a Map to data-sly-attribute, that should do the trick.

To set multiple attributes, pass a map object hold key-value pairs corresponding to the attributes and their values. For example, assuming,

attrMap = {

    title: "myTitle",

    class: "myClass",

    id: "myId"

}

Then,

<div data-sly-attribute="${attrMap}"></div>