1

I've got a content type article. I display them on a view blog.

I'm customising the display via views-view-fields--blog.html.twig. I'd like to display the author and date fields (they are configured in the view). The other fields display fine, but how do I access those two?

<div class="blog-article">
  <div class="blog-image">
    <a href="blog-single-right-sidebar.html">{{ fields.field_image.content }}</a>
  </div>
  <div class="blog-details">
      <!-- Here is where I need the author and date fields -->
      <div class="blog-date">
        Posted by <a href="blog-masonry-2columns.html">{{ ??? }}</a> | {{ ??? }}
      </div>
      <div class="blog-title">{{ fields.title.content }}</div>
      <div class="blog-short-description">{{ fields.body.content }}</div>
  </div>
</div>
  • Is it not just {{ fields.created.content }}? – Kevin Feb 13 '17 at 16:22
3

I've added both node created and node changed fields to my views before, this is how I output them:

<span class="label">Date Created:</span> {{ fields.created.content }}
<span class="label">Date Modified:</span> {{ fields.changed.content }}

I assume user would work the same way. It will render in whatever way the view field is configured.

For example: {{ fields.uid.content }}

  • {{ fields.created.content }} works! What about the author though? How can I check for all these variables? – Pim Feb 13 '17 at 16:24
  • Its based on the fields you added to your view output and likely the field name in the view (akin to machine name). So if you relate the user to the node, then add a field called 'User', I suspect the variable is then {{ field.user.content }}. – Kevin Feb 13 '17 at 16:25
  • It was {{ field.uid.content }} :-). I could only see the machine name by checking the link with the web inspector in the views admin. Any easier way? – Pim Feb 13 '17 at 16:29
  • I believe I hovered on the item in the views config and looked at the browser bar to figure out the name. I suppose you can also debug the incoming variables and figure it out as well with twig xdebug maybe. – Kevin Feb 13 '17 at 16:33

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.