3

I have to make a small website using drupal 8 for a school project but I keep getting stuck with the twig templating. I'm trying to wrap a div around certain fields in drupal 8 with twig. The layout at the moment is as follows(this is an example);

<div>
Content type image
</div>
<div>
Content type Title
Content type Category
</div>

Is there any way to accomplish this using a twig template for the certain view?

enter image description here

The bottom two items have to go in a div.

1

To add CSS classes you don't need to use Twig, you can do it using the Views UI

Click on your field. Then under style settings, checkmark customize field HTMl and select DIV as your element. Checkmark create css class and type your class name.

enter image description here

1

In node.html.twig Twig you would do it like this:

<div class="cool">
  {{ content.title }}
</div>
<div class="kewl">
  {{ content.field_name }}
</div>
  • The excercise is using twig though, but It's interesting seeing that you can just use the views interface. Is there any way of calling just the image field for example in twig? Something like {{ content.field_image }} ? – Joren Polfliet Apr 17 '16 at 8:59

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.