I have created a views slider block in which have the following fields; image, title, text, and position. What I would like to do is look at the value of the position element and then add an css class to the title and text field to either display on the left or right side of the image.

In Drupal 7 I could do this very easily, but I can't figure out for the life of me how to do this in Drupal 8. I am overriding the views-view-fields.html.twig file.

Normally in Drupal 7 I would get the node ID, load it and then check the position value. In Drupal 8 using views-view-fields.html.twig file all I get is the rendered value (which contains html markup that I don't want).

Trying the preprocess route for the views-view-fields template file, I have the same problem in that value is already marked-up and no way to get the node that it came from.

If anyone has any suggestions how to go about accomplishing this, that would be fantastic.

1 Answer 1


In Drupal 8 using views-view-fields.html.twig file:

{{ row._entity.field_example.value }}

Trying the preprocess route for the views-view-fields template file:

$node = $vars['row']->_entity;
$field_value = $node->field_example->value;
  • Thank-you very much that worked great! One side question, if the returned value is a taxonomy id value, how would you get the associated taxonomy title?
    – user5013
    Commented Nov 20, 2016 at 21:00
  • that should work with {{ row._entity.field_tags.entity.label }} or $node->field_tags->entity->label()
    – 4uk4
    Commented Nov 21, 2016 at 7:30

Your Answer

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

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