Search code examples
typo3typoscriptfluid

HTML in language files


I made custom validation errors for an extension. Now I want to add an HTML link to an error message. tried to put HTML in language files (locallang.xlf) but it doesn't work.

Is there a way around this ?


Solution

  • You can use CDATA to encapsulate the HTML:

    <target><![CDATA[Here is <a href="https://...">useful info</a>]]></target>
    

    You should consider generating the link URI from the outside and pass it as argument. Your translation could then look like this:

    <target><![CDATA[Here is <a href="%s">useful info</a>]]></target>
    

    In a Fluid template you would then do this:

    <f:translate key="translation-id" arguments="{0: '{f:uri.typolink(...)}'}"/>
    

    This would have the advantage that you can freely customize the link e.g. via TypoScript constants/setup.