I am currently working on components for AEM 6.0, I've noticed a quite strange behavior of the data-sly-attribute sightly attribute and I'm wondering if this is something that has been noticed by others (maybe a bug).
Take the following code:
TEMPLATE (html)
<div id="${properties.divId}"
data-sly-use.attr="com.something.sightly.promoModel"
data-sly-attribute="${attr.attributeMap}">
<a href="www.example.com"
class="btn btn-transparent"
data-sly-attribute.target="${properties.ckbNewWindow}"
**data-sly-attribute="${attr.attributeMap}"**>
${properties.ctaText}
</a>
</div>
Model (java)
public class PromoModel{
protected HashMap<String, String> attributeMap = new HashMap<String, String>();
@Override
public void activate() throws Exception {
attributeMap= ComponentUtils.buildDataAttributeMapFromResource(Constants.DATA_ATTRIBUTES_FIELD, getRequest());
}
public HashMap<String, String> getAttributeMap(){
return attributeMap;
}
with buildDataAttributeMapFromResource function that basically populates the HashMap based on what content is in the component.
The issue is, when this code is executed on Author it works great but when I execute it on a Publisher the:
class="btn btn-transparent"
does not render. It seems like data-sly-attribute is overwriting it and thus erasing it because if I change my template to this:
<div id="${properties.divId}"
data-sly-use.attr="com.something.sightly.promoModel"
data-sly-attribute="${attr.attributeMap}">
<a **data-sly-attribute="${attr.attributeMap}"**
href="www.example.com"
class="btn btn-transparent"
data-sly-attribute.target="${properties.ckbNewWindow}">
${properties.ctaText}
</a>
</div>
Notice that
data-sly-attribute="${attr.attributeMap}"
is in front of
class="btn btn-transparent"
it renders perfectly fine on Author and Publisher.
Bug ? Maybe there is a fix for this out there that I'm not aware of ... ? Any advice would be great.
Thanks Nicola