How do I get the node URL in a Twig template?

Solutions

In a node.html.twig you can directly use {{ url }}

<a href="{{ url }}">read more</a>

For more information read comment in core template : /core/modules/node/templates/node.html.twig :

{#
/**
 * @file
 * Default theme implementation to display a node.
 *
 * Available variables:
 * - node: The node entity with limited access to object properties and methods.
 * ...
 * - url: Direct URL of the current node.
 * ...
#}
...

<article{{ attributes }}>

  {{ title_prefix }}
  {% if not page %}
    <h2{{ title_attributes }}>
      <a href="{{ url }}" rel="bookmark">{{ label }}</a>
    </h2>
  {% endif %}
  {{ title_suffix }}

According to Functions - In Twig Templates you can use is simple by

 {{ path('entity.node.canonical', {'node': node.id}) }}

I have found this solution that works, but is quite convoluted.

{{ path('entity.node.canonical', {'node': content['#node'].id()  }) }}
Tags: Theming / Nodes / Uri

Similar questions

Get path/url/uri of Entity reference field to content in a Twig template?
I have a Entity reference field which links to internal content/node. I can get the title with {{ node.field_related_project_internal.entity.label }} But how can I get the raw path/url/uri of the linked content/node? The soloutions for a Link Field to not work here: How to get the valid URL of a Link field from within a Twig template?
Can't get url from internal uri in twig template file
I have tried every suggestion I could find and nothing is working. I need to get the actual path or url since I am adding some specific classes to the link. The array is below I got to this from the following I understand that I need to use the url() or path() function but these require 2 parameters and I am unsure where to get these from.
How do you get the url of an image in a view twig template?
I want to check the fields.field_image.content to see if it is empty or not. I want the view to display differently if there is no image in the page field_image field. I was thinking I could just get the URL of the field_image and do a simple if statement, but I don't see a way to do that. Is there to check if the fields.field_image.content field i...
In my Simplenews twig template how do I get the URL of the page I am emailing?
When a single test newsletter is sent, Drupal provides me with the expected URL as follows: Or by using the trim Twig function But when sending the actual newsletter issue to subscribers, the batch process causes the url(‘current’) to provide a batch url like https://my-site.uk/batch How can I obtain the one I want (to direct newsletter recipients ...
How can i get the list of images url's in twig template, Drupal 8?
I have a content type with image field limited to 10 images. I need to get the list of url's to create a slider in the template. I'm able to access the first url using the below code. How can i get the full list of images respective to each node? I need my template to be populated as below
Twig template suggestions for paths such as page--node--page-url
using D8, I'd like a twig template for a page I've created based off the path of the page and not node %. I look in my twig suggestions and all I see are: As template suggestions. However, as I'm working in multiple environments and don't know what the node number will be when I actually create this page I'd like to just base it off the path I've s...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.