This forum is for assistance with theme development.

naming twig

Hi! How can I set name to page template depending on the type of material in drupal 9? Thanks.

Adding content between body and comment

Hi there,

I'm trying to add some content between the node content and the comment section.

I use a custom theme based on Classy.

The node.html.twig template in the Classy theme contains this section:

  <div{{ content_attributes.addClass('node__content') }}>
    {{ content }}
  </div>

The content placeholder gives out both the body content and the comment section.

How would i seperate these two, so i can place other content (exaple: block) between the body content and the comment section?

I appreciate any help with this.

field_link Add class

So, I know I can do this through preprocess or even creating a field formatter.

Let's say I don't feel like doing all of that because I consider it overhead. I went and use the following

{{ content.field_link[0]|merge({'#options': {'attributes': {'class': ['your-class my-class']}}}) }}

Now, I had the template for field_link overwritten, and I noticed that when I used this option it stopped using my template. Is there a way to add a Class to a field_link in Twig without it breaking your template?

How to show html depending on current language?

i need something like this:

if (language == en)
    <div class="fancy-box-en"></div>
else if (language == fr)
    <div class="fancy-box-tr"></div>
else if ....etc
endif

Acess paragraph's child fields using content

Hello,

I have the following question. I have a paragraph with the following structure:

Paragraph

- field_paragraph_content

  - field_image

It's a paragraph inside a paragraph

From the Parent Twig Paragraph I want to access what would be in the child's Twig the field content.field_image

My requirement is to print the image at the same level of field_paragraph_content but I don't want to manually create the img tag or use drupal_image() or having to manually declare the Image Styles.

Connecting custom content types to the main menu using Twig template

I created a content type with the name 'Brand' and a field that contains three categories which are separate pages on the website. Each of those categories are also shown in the menu. Now I want to create a submenu below each category in the menu where the 'Brand' pages are shown which are connected to the selected category. Is there a way to do this in Twig?

Currently I have the following template where I want to show the items.

Pages

Subscribe with RSS Subscribe to RSS - Theme development