At work we let Jenkins run xmllint on our TYPO3 fluid template files to catch bugs before they get deployed.
This requires well-formed template files, and one of the challenges is to keep them well-formed even when tags and attributes need to be created dynamically depending on conditions.
Dynamic attributes
The following template is not well-formed and xmllint will error out:
<div {f:if(condition:data.isbig, then:'class="big"')}>..</div>
The solution to this problem is to set a variable if the condition matches and use that in the attribute:
<f:if condition="{data.isbig}"> <v:variable.set name="divclass" value="big"/> </f:if> <div class="{divclass}">..</div>
Dynamic tags
<{settings.type}>..</{settings.type}>
<v:tag name="{settings.type}">..</v:tag>