8.4.7 attribute
The attribute instruction can be used to add attributes to an element in a dynamic way.
Specifying the attribute name at runtime
Using t:attribute, the attribute name can be specified using expressions:
<div>
<t:attribute name="my-${something}" value="music"/>
</div>
The name can include a namespace prefix. As usual for attributes, the default namespace (= no prefix specified) does not apply.
Adding attributes conditionally
You can surround the attribute with conditional logic (such as an
<div>
<t:if test="${1 < 3}">
<t:attribute name="class" value="music"/>
</t:if>
</div>
Attribute instructions should be the first children of an element, thus immediately follow a start-tag. They can not be used anymore once child content for the element is generated. So the following is not possible, as there is no start-tag to add the attribute to:
<div>
Hello world.
<t:attribute name="my-${something}" value="music"/>
</div>
If you don't need the above mentioned dynamism when adding an attribute, you can as well add the attribute directly on the element. So you can then simply do:
<div class="music"> </div>
Previous