How to include a view mode in a template in order to add more to it?

Hi everyone,

I’ve done some test in the past to add a banner on top of a node (content type : update) when a checkbox in our form is checked. To do so, i’ve set the display mode of our content type update to default and used a template to render it properly (see code below).

{% if node.field_banner.value == 1 and content.field_listing_image|render %}
  <div class="banner-img-updates">
    {{ content.field_image_banner|render ? content.field_image_banner|render : content.field_listing_image|render }}
  </div>
{% endif %}
<div class="body-updates">
  <h1>{{ label|render }}</h1>
  <p>{{ date }} | By {{ content.field_author }}</p>
  {{ content.body|render }}
</div>

This all worked great.

After playing around it seems that the view mode which is the most appropriate for us is the Full content view mode with News Full content layout.

Our issue now is the following : how can we reuse this display mode and add the banner feature as seen above ?

I’ve created a new template and tried out different names, according to the naming convention :

node--update--full-content.html.twig
node--update--fullcontent.html.twig

But nothing seems to work. I’ve also looked up the machine name of this View mode (node.full) and tried out with that but same issue.

Here is what i’m trying to accomplish with this template :

 {% if node.field_banner.value == 1 and content.field_listing_image|render %}
  <div class="banner-img-updates">
    {{ content.field_image_banner|render ? content.field_image_banner|render : content.field_listing_image|render }}
  </div>
{% endif %}
<div class="body-updates">
  {{ content|render }}
</div>

Do you guys have any experience trying to decorate an existing view mode ?

Thank you very much.

Maxime

Hello Maxime,

Can you please provide URL and content type?

Also some quick debug questions:

  • Did you clear the caches after modifying the template?
  • Did you add the field in Manage Display of the Full Content? If you didn’t then its not visible in the template.

Also the name of the template should be node--<machine_name_of_content_type>--full.html.twig.

Konstantinos

Hi @kplatis,

Thanks for your answer :slight_smile:

Yes i cleared the cache.

Here is the URL of our website. You’ll find it under Content type > Update. Regarding the template you can find it on the server under templates/nodes/node--update--full.html.twig

As you recommended, i changed the name and added the two fields : field_image_banner and field_listing_image as visible in Manage Display of the Full Content. However i still get the same issue.

Thank you very much.

Maxime

Hey Maxime,

I checked your display settings and apparently you have assigned the Full Content to be rendered using a pattern. The patterns are predefined templates meaning that when you select to render your node as a pattern, the template of the pattern takes over and renders your node using this specific pattern.

Change the layout to -None- to see if it works

Konstantinos

Hi @kplatis,

I see. Has the News Full Content layout template been developed by you guys ? It’s actually the one i’d like to override, so if i select None then i loose it all :laughing:

Maxime

Just found the pattern on your Git repo. I thought there could be a way to keep the pattern as it is but just decorate it with a banner if a checkbox field would be checked.

Maxime