In my preprocess function I have variables with the route name and route parameters:

function my_theme_preprocess_node(&$variables){
  $variables['route_name'] = $route_name;
  $variables['route_parameters'] = $route_parameters;

How do I pass them to the following link function in my page.html.twig file:

{ <a href="{{ path('$route_name', {'node': $route_parameters}) }}">Link to the object with $route_name and $route_parameters</a> }

Is it at all possible?


The '$' isn't used in twig to designate a variable. This code should work:

<a href="{{ path(route_name, {'node': route_parameters}) }}">
   Link to the object with {{ route_name }} and {{ route_parameters }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.