'TYPO3 - f:link.typolink with additionalAttributes and a condition?

I am looking for a solution, how to include a query in additionalAttributes?

Static:

<f:link.typolink parameter="{field.referenceLink}" title="{field.referenceTitel} - {field.referenceText}" additionalAttributes="{rel:'nofollow'}">
    Link
</f:link.typolink>

condition:

<f:variable name="nofollow"><f:if condition="{field.referenceLinkNofollow}"><f:then>{rel:'nofollow'}</f:then><f:else>{rel:'dofollow'}</f:else></f:if></f:variable>

next Test:

<f:section name="nofollow">
    <f:spaceless><f:if condition="{field.referenceLinkNofollow}"><f:then>{rel:'nofollow'}</f:then><f:else>{rel:'dofollow'}</f:else></f:if></f:spaceless>
</f:section>

Dont Work like this:

<f:link.typolink parameter="{field.referenceLink}" title="{field.referenceTitel} - {field.referenceText}" additionalAttributes="{nofollow}">
    Link
</f:link.typolink>

Error:
The argument "additionalAttributes" was registered with type "array", but is of type "string" in view helper "TYPO3\CMS\Fluid\ViewHelpers\Link\TypolinkViewHelper".



Solution 1:[1]

This should also work if {field.referenceLink} and {field.referenceLinkNofollow} contains needed data.

    <f:link.typolink parameter="{field.referenceLink}"
                     additionalAttributes="{f:if(condition: '{field.referenceLinkNofollow}', then: '{rel:'nofollow'}')}"
    >Linktext</f:link.typolink>

Solution 2:[2]

thanks, it works!

<f:variable name="nofollow" value="{f:if(condition: '{field.referenceLinkNofollow}', then: 'nofollow', else: '')}" />

fluid:

<f:link.typolink parameter="{field.referenceLink}" title="{field.referenceTitel}" additionalAttributes="{rel: '{nofollow}'}">

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Sebastian Schmal