How to get the valid URL of a Link field from within a Twig template? I have a Link field named field_my_link (machine name).

Within a Twig template I can get the link's URL value with this:

{{ node.field_my_link.uri }}


If inside the Link's URL there is an external URL, e.g. http://example.com it works good.

But, if inside the Link's URL there is stored an internal URL, e.g. "/node/11", I get a value like this:

"internal:/node/11"


with the "internal:" prefix.

How can I get the valid URL?

For example, if the link's URL is "http://example.com" I want "http://example.com" (this already works), if the link's URL is "/node/11" I want the relative URL "/node/11", if the link's URL is "&lt;front&gt;" I want the URL "/", etc.



EDIT

I can get the value I want within a PHP preprocess function, using this:

$url = $variables['node']-&gt;get('field_my_link')-&gt;first()-&gt;getUrl();


How can I access the same value within the Twig template?

I know I can do this within the preprocess function:

$variables['my_url'] = $url;


Then access the url within Twig using {{ my_url }}, but I would avoid to write a preprocess function each time I have a link field.
Your PHP from your latest edit would translate into twig like this:

{{ node.field_my_link.0.url }}


This works like this, 0 returns the first item of the field item list, url gets the url object and because twig will cast this object as a string this will call the magic method toString() and will output the url as a string value.

You only need to use url, because twig looks automatically for the method getxyz() if there is no property with that name xyz.