m4a
m4a

Reputation: 141

How to set the link-title as Linktext with f:link.typolink viewhelper in TYPO3 9.5

I have build a custom content element with a link from field "header_link".

How can I set the title of that link as link text?

In the fluid template I use the link.typolink viewhelperin this way:

<f:link.typolink parameter="{data.header_link}" class="btn btn-primary" />

This results in

<a href="/page" title="link title" class="btn btn-primary">Page Title</a>

How do I set the link title as link text instead of the page title?

Upvotes: 5

Views: 4814

Answers (2)

HenryAveMedi
HenryAveMedi

Reputation: 206

since TYPO3 10.3 it can be done like this

<f:link.typolink parameter="{data.header_link}" parts-as="parts">
  {parts.title}
</f:link.typolink>

read more in the changelog documentation

these are all the parts u can use

<f:link.typolink parameter="123 _top news title" parts-as="parts">
   {parts.url}
   {parts.target}
   {parts.class}
   {parts.title}
   {parts.additionalParams}
</f:link.typolink>

Upvotes: 13

Oliver Hader
Oliver Hader

Reputation: 4203

<f:link.typolink parameter="{data.header_link}" title="Title Attribute">
    Custom Link Text
</f:link.typolink>

results in

<a href="/page" title="Title Attribute">
    Custom Link Text
</a>

Reference


Update 1

(updated from additional comments)

Combined parameter string t3://page?uid=123 - - "title" (parameter target class title additional parameters) is supposed to only have affect on generating the anchor tag. There is no out-of-the-box way to use the title part as variable in a Fluid template.

In order to do that, a custom ViewHelper would have to be created, e.g.

class ParameterPartViewHelper extends AbstractViewHelper
{
    public function initializeArguments()
    {
        $this->registerArgument('part', 'string', 'Parameter part to be extracted', true);
    } 

    public function render(): string
    {
        $part = $this->arguments['part'] ?? null;
        $typoLinkCodec = GeneralUtility::makeInstance(TypoLinkCodecService::class);
        return $typoLinkCodes->decode($this->renderChildren())[$part] ?? '';
    }

That could be used in Fluid e.g. like this

<f:link.typolink parameter="{data.header_link}" title="Title Attribute">
    {data.header_link -> my:parameterPart(part:'title')}
</f:link.typolink>

Upvotes: 6

Related Questions