In Summary
if you want to generate Relative Url use path
and if you want to generate Absolute Url use url
So the solution for this question is
for relative URL
path('entity.node.canonical', {'node': node.nid})
and for absolute URL
url('entity.node.canonical', {'node': node.nid})
Also, I've provided some details about the path
, url
and link
functions to help other guys received this question ( as I received mine after 1 year)
url($name, $parameters, $options)
Generate an absolute URL given a route name and parameters:
<a href="{{ url('view.frontpage.page_1') }}">{{ 'View all content'|t }}</a>
Generate an absolute URL to the current url:
<a href="{{ url('<current>') }}">{{ 'Reload'|t }}</a>
Generate an absolute URL to the front page:
<a href="{{ url('<front>') }}">{{ 'Home'|t }}</a>
path($name, $parameters, $options)
Generates a [relative] URL path given a route name and parameters.
{# Link to frontpage view. #}
<a href="{{ path('view.frontpage.page_1') }}">{{ 'View all content'|t }}</a>
{# Link to user entity/profile page. #}
<a href="{{ path('entity.user.canonical', {'user': user.id}) }}">{{ 'View user profile'|t }}</a>
{# Link to node page. #}
<a href="{{ path('entity.node.canonical', {'node': node.id}) }}">{{ 'View node page'|t }}</a>
The url and path function are defined in close parallel to those found in \Symfony\Bridge\Twig\Extension\RoutingExtension.
link($text, $url, $attributes)
This helper function accepts as first parameter the text and as second parameter the url
Examples:
{{ link(item.title, item.url, { 'class':['foo', 'bar', 'baz']} ) }}
file_url($uri)
This helper function accepts a relative path from the root and creates a relative URI path to the file.
{{ file_url(node.field_example_image.entity.uri.value) }}
front page template
, it is not current page<a href="/about-us">
instead of using some function to get it?