Adding additional tag attributes with additionalAttributes

At the moment most of the ViewHelpers can be split into two types: One group of ViewHelpers is rather functional oriented. That applies for example to the format ViewHelpers, which can format data or currencies. The other group is mostly output oriented, because these ViewHelpers output mostly a HTML tag. Samples of this are the form ViewHelpers, all of them start with f:form . Every form ViewHelper generates a HTML tag, like e.g. <form> or <input> .

A Fluid ViewHelper supports most attributes that are also available in HTML. There are for example the attributes class and id which exists in all tag based ViewHelper. You find a listing of all universal properties in the appendix C.

However, sometimes attributes are needed that are not provided by the ViewHelper - maybe a special JavaScript event handler or proprietary attributes (which are used by JavaScript frameworks like Dojo for example). To output them as well without changing the ViewHelper, the attribute additionalAttributes is available. This is an associative array by which additional tag attributes can be defined, like the following example shows:

<f:form.textbox id="myTextbox" additionalAttributes="{onclick: 'alert(\'Hello World\')'}" />

Another common use case is the data-attribute, which can be used in JavaScript functions:

<f:form.textbox additionalAttributes="{data-anything: 'some info'}" />

The HTML tag generated by the ViewHelper now also supports the onclick attribute:

<input type="text" onClick="alert('Hello World')" id="myTextbox" />

The additionalAttributes is especially helpful if only a few of this additional attributes are needed. Otherwise it is often reasonable to write an own ViewHelper which extends the corresponding ViewHelper.

additionalAttributes is provided by the TagBasedViewHelper , the base class for tag based ViewHelpers (see appendix C) and it allows the adding of optional attributes for the HTML tag output.