1

I'm fairly new to theming with Drupal, especially using Templates and Twig. After a lot of searching and experimenting I seem that have accomplished my desired view mode the way I want...almost.

I have a field in my content type called Category. The machine name is field_category. I have been able to output the field in my template using the key: {{content.field_category}} But as you can see it also applies a CSS styling I have on the full default Node Page which I would prefer not to have it there.

Twig Template Category Field Output

Going at it a different way, I used a View along with the given replacement patterns and was given the token of {{ field_category }}. After everything was done it does the same thing without any CSS styling since it's not pulling in the HTML markup of class="field field--name-field-category".

Views Category Field Output

My question is I wonder if there is a way to grab the value without the markup? And if so how? Any steps in the right direction would be very much appreciated, I am a complete beginner at Drupal and even more so with Twig. Thank you.

2
  • 1
    {{ content.field_category[0] }} will likely do the trick
    – No Sssweat
    Aug 25, 2016 at 8:33
  • That absolutely did do the trick, thank you for your help! I kept on getting issues when using Kint or Dump and wasn't able to fix this by myself but your answer did work. Aug 25, 2016 at 19:22

1 Answer 1

2

With Drupal 8 you now have two ways to access to the data of a given node/entity.

The first is with the {{ content.* }} this will return the content that went through the display plugins/system (everything which you configure in the "Display mode" of the content type).

You also can access to the raw data with {{ node.*.value }}

It's preferably that you use the way {{ content.* }} as much as possible in order to be able to use the power of Drupal to quickly change the things with display mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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