0

I'm putting together a view with multiple content types. In my my_theme.theme file I want to set the template suggestion based on the item's content type (e.g. Content-Type-A gets Template-A.twig and Content-Type-B gets Template-B.twig). Digging through the $variables[] array I can't find if or where there is an element that specifies the content type for the current view row.

Does any know how I may determine the content type of view row in the $variables[] array? If it's not in there what's the best way of adding it?

Thanks!

  • Wouldn’t it be easier to create a view mode or something for this purpose? I mean you’re already creating the twig files this route. – Kevin Sep 4 at 23:54
  • 2
    add a hidden field to the view with the node type then you can use {% if type== 'x'%} do stuff {%endif%} – Taggart Jensen Sep 5 at 6:02
0

Create a new display mode and use this display mode on the view. then each of this display mode can be altered in admin or custom template can be made.

  • I'm not sure that I can rely on display modes. For my teasers used in the view, I'm pulling in statistics such as comment and view count. To do this (as far as I know) is to use "fields" instead of "content" and therefore display modes won't help. Thanks though :). – mrlexington Sep 5 at 15:14

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.