Kauri Documentation
 PreviousHomeNext 
8.4.6 @inheritBook Index8.4.8 block

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 if) to conditionally add the attribute:

<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>
 PreviousHomeNext 
8.4.6 @inherit8.4.8 block