Distinguish internal and external link

Hello everyone

I have a question concerning the Neos.Neos/Inspector/Editors/LinkEditor. When using this I can see in the backend, that a different Icon is used depending on the link target. Neos is able to distinguish between internal links (page icon) and external links (external link icon).

I would like to automatically set a _target="blank" for external links in one NodeType. However I think Neos does not parse this information so I can use it. Is that correct? Is there a way to check for if a link is internal or external in Fusion or in the templates?

This is done by the fusion prototype Neos.Neos:ConvertUris that is usually applied to all items that may have editable-urls via processor @process.convertUris = Neos.Neos:ConvertUris
https://neos.readthedocs.io/en/stable/References/NeosFusionReference.html?highlight=_blank#neos-neos-converturis

For making sure the attribute is added the Neos.Neos:ConvertUris has to work on the whole item and not only the url-attribute because otherwise it cannot modify other properties.

I already do this in my NodeType.fusion. Could you tell me how my fluid template would have to look? Currently I have the following:
Fluid Template:

<a href="{destinationLink}" title="{destinationTitle}">
   {destinationTitle}
</a>

Fusion:

destinationLink = Neos.Fusion:Case {
    backend {
        condition = ${node.context.inBackend}
        renderer = '#0'
    }

    default {
        condition = TRUE
        renderer = ${q(node).property('destinationLink')}
        renderer.@process.convertUris = Neos.Neos:ConvertUris
    }
}

Add the @process.convertUris = Neos.Neos:ConvertUris to the whole prototype and not just the single property.

prototype(Vendor.Site:Content) {
   destinationLink = ${q(node).property('destinationLink')}
   destinationLink.@process.beDummy = '#0' 
   destinationLink.@process.beDummy.@if.inBackend = ${node.context.inBackend}

   @process.convertUris = Neos.Neos:ConvertUris
}

Hm, this still does not work for me. In the template I so far have the following:

<a href="{destinationLink}" title="{destinationTitle}">
    {destinationTitle}
</a>

But here the target attribute can not be added by Neos. Another way would be to use

<neos:link.node node="{destinationLink}">
    {destinationTitle}
</neos:link.node>

But this viewhelper is only for nodes and I get an error when entering an external link in the Neos backend: Paths must not contain two consecutive slashes.

So how can I set it up, so my output can work with internal and external links and add the target="_blank" automatically?

Did you add this to the fusion prototype that renders the template?

Yes, my fusion looks like this:

prototype(Acme.ThemeName:Region) < prototype(Neos.Neos:Content) {

  destinationLink1 = ${q(node).property('destinationLink1')}
  destinationLink1.@process.beDummy = '#0'
  destinationLink1.@process.beDummy.@if.inBackend = ${node.context.inBackend}

  @process.convertUris = Neos.Neos:ConvertUris

}

We actually have 3 of these destination links in our NodeType, but I left the other ones out for simplicity.

Can you try this:

prototype(Acme.ThemeName:Region) < prototype(Neos.Neos:Content) {
  @process.convertUris = Neos.Neos:ConvertUris {
      externalLinkTarget = '_example_external_' 
      resourceLinkTarget = '_example_resource_' 
   }
}

Just to verify, both should be _blank by default but who knows.

What should I use in my template in this case? The neos:link.node? I am sorry, I am fairly new to Neos, fusion and fluid…

<a href="{destinationLink}" title="{destinationTitle}">
  {destinationTitle}
</a>

The nodeLink expects a node-object but the link you get should actually be a string that looks like “http://…”, “node://identofier” or “resource://_identifier”.

You can verify this if you comment the @process out. Then you should see “node://…” as href for internal links.

OK, so far when I comment out the @process, I see the internal links as “node://…” links. So the @process works and creates useful URIs. But in this template Neos could not possibly add the target="_blank" or am I mistaken?

The processor should add the missing target attribute for external urls. So this should be just fine.

Which version of Neos are you using.

I am currently on Neos 4.2.9. Strange, so this behaviour actually has never worked in any project for me. I never saw a target attribute being added like this.