0

I have a view that has the fields: Content: ID, Content: Title and Content: Path.

In my views-view-module.html.twig file I can access the fields via the following:

{{ item['#row']._entity.id }}

{{ item['#row']._entity.title[0].value }}

But I cannot seem to retrieve the path field using:

{{ item['#row']._entity.path[0].value }}

Do I do this the same way or am I missing a trick? I've tried to use dump/kint but I keep getting the WSOD.

Can anyone offer me a solution?

Thanks in advance

0

You access the fields from the entity. That are not the fields from the view. And in the entity there is no field path.

Look for the path in the row content. This is a good advice not only for the path, but for all fields, because in the entity the field values are the raw data from the database and not formatted for output. That doesn't make a difference for the id and the title though, because they are plain alphanumeric, but you really should do it for more complex fields. And for computed fields like path you have no other choice, if you don't want to compute the field again yourself.

  • Could you please elaborate. How can I access the variables.. via the view object or the rows variable provided at the views-view-unformatted.html.twig level? – cwiggo Oct 17 '16 at 11:51
  • At the top of each twig it is documented which variables are available and how to use them. In this template you find the content in {{ row.content }}. – 4k4 Oct 17 '16 at 11:58
  • I have had difficulty enabling the kint/dump for twig. So what would I need to add to access the "Content: path" variable? – cwiggo Oct 17 '16 at 12:00
  • You can't tell, if you don't know the view. If you can't find the path, it is possible you did not configure the view correctly. You can try other views templates. But read the documentation of each template which variables to use. And for each template you have to use another configuration of the view. – 4k4 Oct 17 '16 at 12:48

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.