Output HTML attribute name with HTL | Community
Skip to main content
Adobe Champion
May 31, 2017
Solved

Output HTML attribute name with HTL

  • May 31, 2017
  • 5 replies
  • 1603 views

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?

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

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>

5 replies

smacdonald2008
June 1, 2017

Check the Spec to gain access to objects -- htl-spec/SPECIFICATION.md at master · Adobe-Marketing-Cloud/htl-spec · GitHub

Are you referencing a valid object.

Adobe Champion
June 1, 2017

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.

MC_Stuff
June 1, 2017

Hi Joshua,

data-sly-attribute at https://docs.adobe.com/docs/en/htl/docs/block-statements.html might help.

Thanks,

Feike_Visser1
Adobe Employee
Feike_Visser1Adobe EmployeeAccepted solution
Adobe Employee
June 1, 2017

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>

Adobe Champion
June 1, 2017

That worked.  Thanks Feike!