So I created a block view showing a Unformatted list of text and image fields. Now I would like to style the output.

I can create a twig file for that block. But how can I iterate through the content? What I would like to have is basically the text and the image link for each row.

Edit: So one solution is to add to the theme.theme file

* Implements hook_theme_suggestions_HOOK_alter().
* Add a suggestion given by the url of the node.
function mytheme_theme_suggestions_views_view_unformatted_alter(array &$suggestions) {
  $url_fragments = explode('/', \Drupal::request()->getRequestUri());
  if (count($url_fragments) > 1) {
    $suggestions[] = 'views_view_unformatted__' . $url_fragments[1];

and then create a views-view-unformatted--.html.twig which will then only act on http://example.loc/<the_node>. But I am still looking for a solution to iterate through the rows. Also this won't work if we change the path of a node.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.