Skip to main content
expanded example
Source Link
Sam
  • 529
  • 1
  • 10
  • 27

I want to have two different templates for the same field on a node template.

For example:

   <div <h1>class="navigation>{{ content.field_section }}</h1>div>

    // uses paragraph--section.html.twig 
    // Only want to print the titles from paragraph sections
    <h2>    
<section>{{ content.field_section }}</h2>section> 
    // uses paragraph--section2.html.twig
    // Want to print the body and titles from paragraph sections

How can I do this? Is there a way to flag one instance or force a specific template?

I want to have two different templates for the same field on a node template.

For example:

    <h1>{{ content.field_section }}</h1>
// uses paragraph--section.html.twig
    
    <h2>{{ content.field_section }}</h2> 
// uses paragraph--section2.html.twig

How can I do this? Is there a way to flag one instance or force a template?

I want to have two different templates for the same field on a node template.

For example:

<div class="navigation>{{ content.field_section }}</div>

    // uses paragraph--section.html.twig 
    // Only want to print the titles from paragraph sections
        
<section>{{ content.field_section }}</section> 
    // uses paragraph--section2.html.twig
    // Want to print the body and titles from paragraph sections

How can I do this? Is there a way to flag one instance or force a specific template?

edited title
Link
leymannx
  • 18.8k
  • 6
  • 72
  • 126

8 Different TemplateTemplates for Same Field

Source Link
Sam
  • 529
  • 1
  • 10
  • 27

8 Different Template for Same Field

I want to have two different templates for the same field on a node template.

For example:

    <h1>{{ content.field_section }}</h1>
// uses paragraph--section.html.twig
    
    <h2>{{ content.field_section }}</h2> 
// uses paragraph--section2.html.twig

How can I do this? Is there a way to flag one instance or force a template?