Below is a twig template: core/modules/views/templates/views-view-unformatted.html.twig:

 * @file
 * Default theme implementation to display a view of unformatted rows.
 * Available variables:
 * - title: The title of this group of rows. May be empty.
 * - rows: A list of the view's row items.
 *   - attributes: The row's HTML attributes.
 *   - content: The row's content.
 * @see template_preprocess_views_view_unformatted()
 * @ingroup themeable
{% if title %}
  <h3>{{ title }}</h3>
{% endif %}
{% for row in rows %}
  <div{{ row.attributes }}>
    {{ row.content }}
{% endfor %}

How do I alter the markup (and add some php logic) in row.content? - which outputs markup such as:

<div class="views-field views-field-body">
  <div class="field-content">
    <p>Hello world!</p>

Presumably, there is another twig template for this markup? I cannot find it. I have the twig debugger turned on, but there are no notes above the markup that renders each content field.

I've looked at the template preprocess functions in views.theme.inc too - can't see any markup being generated in those things.


2 Answers 2


theme_views_view_field() is one of the 17 currently remaining theme functions in Drupal 8. This is a special case that is both a theme function and a template, like theme_field() and field.tpl.php in Drupal 7. The fact that there is a still a theme function and that's where the output comes from by default is why you aren't seeing it in the twig_debug output, which only shows output from template files. The issue to fully convert theme_views_view_field() to a template is https://www.drupal.org/node/2348729.


First, enable twig debugging in sites/default/services.yml.

Then that should print a wrapper around each template that tells you which template it is exactly using for that piece of marking. In this case, it is probably views-field.html.twig or so.

Twig also reports what kind of suggestions you can use (e.g. a node type specific template for node.html.twig), but that doesn't work for views because views uses a different approach for that, and twig debug doesn't understand that yet.

  • I've got the debugger on. Getting the template suggestions too. But, it does not tell me anything for that particular piece of markup. I've searched for the string '<div class="views-field' in all D8 code, but can't work out where it comes from.
    – dbj44
    Commented Jan 28, 2015 at 22:55
  • 1
    I voted this suggestion up as all suggestions are printed in the html source. The answer should be views-view-fields plus all suggestions but agree with @24ma13wg ... running into bug drupal.org/node/2118743 as not all suggestions are listed. I use Drupal 8.0.5 Commented Mar 19, 2016 at 16:58
  • I added the Devel Kint kint($hook); in Drupal/Core/Theme/ThemeManager.php ~ line 136 first line within its render() method which at least shows all suggestions. Commented Mar 20, 2016 at 15:44

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.