Search code examples
typoscripttypo3-9.x

Typo3 finding out if a typolink is external or internal?


I've got an element in which I can put in a link to either an internal or external page and I would like to check inside my .html-File if the link is one of both, to then add something specific for internal/external.

Currently my code looks like this:

<f:if condition="{data.header_link}">
      <f:link.typolink
        parameter="{data.header_link}"
        class="btn btn-danger"
      >
        More
      </f:link.typolink>
    </f:if>

Is there a way for me to check if data.header_link links to an internal/external page? I'm using Typo 9.5.14

Thanks for any help!


Solution

  • You could do a check whether the current domain is part (/beginning) of the link.

    Depending on your configuration local links might have no domain at all, which also can be checked.

    Otherwise these kind of checks could also be done in CSS, where you could put content before or after the link.

    /* any lin, as internal links will be redefined it will be external links only */
    a:after { content:"🔱"; }
    
    /* internal link */
    a[href|=https://mydomain.tld]:after{ content:"âž°"; }