Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

Code snippet that can be used to generate URL paths with route name and parameters in twig in drupal 8.

Generate relative paths

using this function  path($name, $parameters, $options) like this:

{#   path= / #}
<a href="{{ path('view.frontpage.page_1') }}">{{ 'View all content'|t }}</a>
{#  path=  /user/1 #}
<a href="{{ path('entity.user.canonical', {'user': 1}) }}">{{ 'View user'|t }}</a>
{#   path /node/1 #}
<a href="{{ path('entity.node.canonical', {'node': 1}) }}">{{ 'View node'|t }}</a>

Generate absolute  paths

using this function  url($name, $parameters, $options) like this:

{# return path like this  http://dev.domaine.com/node/1 #}
<a href="{{ url('entity.node.canonical', {'node': 1}) }}">{{ 'View all content'|t }}</a>

{# return path to current page#}
<a href="{{ url('<current>') }}">{{ 'Reload Page'|t }}</a>

{#  return path to home page #}
<a href="{{ url('<front>') }}">{{ 'Home Page'|t }}</a>

Comments

Add new comment

Restricted HTML

Riadh Rahmi

Senior Web Developer (Drupal & Laravel)

I am a senior web developer, I have experience in planning and developing large scale dynamic web applications especially in Drupal and Laravel.

Web Posts

Search

Page Facebook