Skip to main content
Remove wrong part of answer (the question was not about `file_url`): the right answer is just only after the "Edit"
Source Link

Is this what you are looking for?

file_url($uri)

This helper function accepts a relative path from the root and creates an absolute path to the file.

{{ file_url(node.field_example_image.entity.uri.value) }} 

https://www.drupal.org/node/2486991

Edit:

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.

Is this what you are looking for?

file_url($uri)

This helper function accepts a relative path from the root and creates an absolute path to the file.

{{ file_url(node.field_example_image.entity.uri.value) }} 

https://www.drupal.org/node/2486991

Edit:

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.

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.

added 239 characters in body
Source Link
4uk4
  • 102.9k
  • 7
  • 176
  • 221

Is this what you are looking for?

file_url($uri)

This helper function accepts a relative path from the root and creates an absolute path to the file.

{{ file_url(node.field_example_image.entity.uri.value) }} 

https://www.drupal.org/node/2486991

Edit:

Your PHP code should lookfrom your latest edit would translate into twig like this in Twig:

{{ file_url(node.field_my_link.entity.uri0.value)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.

Is this what you are looking for?

file_url($uri)

This helper function accepts a relative path from the root and creates an absolute path to the file.

{{ file_url(node.field_example_image.entity.uri.value) }} 

https://www.drupal.org/node/2486991

Edit:

Your PHP code should look like this in Twig:

{{ file_url(node.field_my_link.entity.uri.value) }} 

Is this what you are looking for?

file_url($uri)

This helper function accepts a relative path from the root and creates an absolute path to the file.

{{ file_url(node.field_example_image.entity.uri.value) }} 

https://www.drupal.org/node/2486991

Edit:

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.

added 121 characters in body
Source Link
4uk4
  • 102.9k
  • 7
  • 176
  • 221

Is this what you are looking for?

file_url($uri)

This helper function accepts a relative path from the root and creates an absolute path to the file.

{{ file_url(node.field_example_image.entity.uri.value) }} 

https://www.drupal.org/node/2486991

Edit:

Your PHP code should look like this in Twig:

{{ file_url(node.field_my_link.entity.uri.value) }} 

Is this what you are looking for?

file_url($uri)

This helper function accepts a relative path from the root and creates an absolute path to the file.

{{ file_url(node.field_example_image.entity.uri.value) }} 

https://www.drupal.org/node/2486991

Is this what you are looking for?

file_url($uri)

This helper function accepts a relative path from the root and creates an absolute path to the file.

{{ file_url(node.field_example_image.entity.uri.value) }} 

https://www.drupal.org/node/2486991

Edit:

Your PHP code should look like this in Twig:

{{ file_url(node.field_my_link.entity.uri.value) }} 
Source Link
4uk4
  • 102.9k
  • 7
  • 176
  • 221
Loading