I am trying the path($name, $parameters, $options) function in drupal 8 twig .
{{ path(tab_item.entity.field_link.0.url.routeName, tab_item.entity.field_link.0.url.routeParameters) }}

But throwing up error. I am getting the values in tab_item.entity.field_link.0.url.routeName and tab_item.entity.field_link.0.url.routeParameters. but when using them in in path function its throwing unexpected error.

CommentFileSizeAuthor
error.png124.44 KBlomasr

Comments

lomasr created an issue. See original summary.

voleger’s picture

tab_item.entity.field_link.0.url.routeParameters passed in twig function as NULL. Please prepare your values in preprocess hook to be sure that arguments passed in the function have expected types and values.

lomasr’s picture

Sorry about the confusion. tab_item.entity.field_link.0.url is the field value we are getting. This is a paragraph field .

voleger’s picture

Anyway, you should care about the availability of the correct data used as arguments in the twig function.
You can use additional conditional constructions such as https://twig.symfony.com/doc/1.x/tags/if.html
or implements hook_preprocess_HOOK() to prepare the data used in the twig template.

voleger’s picture

Category: Bug report » Support request
Status: Active » Closed (works as designed)

Looks like that was a problem with template customization. So moved to the Support request category.