I have some liferay templates I am attempting to convert from velocity to freemarker.
The old code had some if statements inside html elements. For example:
<a href="url" #if (condition) style="thisStyleOnlyIfcondition" #end> example </a>
Is it possible to have freemarker if statements in an html element? Like this?
<a href="url"
<#if (condition)>
style="thisStyleOnlyIfcondition"
</#if>
>
example
</a>
When I try writing that in video studio code it appears to have errors. I know that the issue is likely the <> characters being in html, but how would I avoid this? Is it possible?
Freemarker doesn't care for anything around its tags, so this is fine
Editors that try to make sense of both, HTML and the templating code (if only for syntax highlighting) are easy to confuse with such syntax that contains what looks like tags within tags.
You could generate a style value before the tag that always gets included, just either empty or with a value, to make the editor happy:
(Pseudocode - validate what works (e.g. for linebreaks), I'm not working with freemarker often. And there might be more elegant solutions)
<#assign conditionalStyle>
<#if condition>
thisStyleOnlyIfcondition
</#if>
</#assign>
<a href="url" style="${conditionalStyle}">...</a>