0

Drupal 8.x

Is it possible to render fields in a view when the display format setting is set to format "Show: Content" ?

For my case, the contrib module I am using has some views integration that provides field data I would like to show, but have found to be difficult to access via preprocess. I also have some programmatically created data I need to show via my template provided by a HOOK_preprocess_HOOK().

I am kind of stuck in the middle. So I am curious if there is a way to render, or maybe get the data of, the forced fields while setting my view to "format: content"?

1 Answer 1

0

Yes, you have to decide whether you want to render Content or Fields. Those are two different concepts in Views. The first renders the entity template in the selected view mode and you configure the fields in the content type. The second renders Views field plugins which you configure in Views UI.

You can approach the issue from both sides:

Show: Content | View Mode

If you start with a View showing content, in the view mode you've selected, display a field for a second View dispay of the same entity. In the second View display select Show: Fields.

You need a module to add the View field to the content type, for example EVA: Entity Views Attachment or Views Reference Field.

Show: Fields | Settings

Or start with showing fields, add a field for the rendered entity

enter image description here

and select a view mode, which you then can configure, preprocess and theme like a normal node template.

1
  • I've used views reference field before and find it a valuable contrib module. Maybe I have been overthinking what I am doing, or maybe was just being stubborn, but the rendered entity was a great choice for my needs. This easily allows me to pull all my preprocess function data into the view. I now have a node teaser display with all fields set to hidden, and just my needed data printed in twig file, rendered as an entity in a views field. Due to how views gets field data, I could not find any other methods. Oct 21, 2018 at 15:32

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.