Questions tagged [theming]

Use it for questions about rendering or modifying the HTML markup produced by a module/theme.

Filter by
Sorted by
Tagged with
-2 votes
0 answers
23 views

Get MenuLinkContent object values

get title and link of a menu link object in. I am trying to get title and link of a MenuLinkContent object and below is my code. I want to get title and link value. How I can get the title and Link ...
-3 votes
0 answers
23 views

How to conditionally load JS based on User Role on Layout Builder?

I'm looking to load a couple of javascript files or functions in layout builder based upon whether someone is an admin or not. I'm not sure if this is something I should be doing in Twig or maybe in ...
0 votes
2 answers
22 views

Error with {{ page.highlighted }} while making a copy of Olivero

I am trying to learn Drupal 9 theming by copying Olivero theme into my themes folder. I copied web/core/themes/olivero to web/themes/olive and then renamed all file names containing 'olivero' to ...
0 votes
0 answers
24 views

How can I display the output of a view with no surrounding templates that can be embedded in an iframe inside another website?

I have a user contextual view which is accessed via a URL like: /user/114/my-view I want to provide the output of this view in a raw format without any surrounding page HTML so that it can be emdedded ...
-3 votes
0 answers
27 views

Navigation button events not working after requesting the javascripts from footer

In Drupal 9 I have find out that the modernizr and touchevents javascript files are requested from the header instead of footer. This causes a render blocking issue while monitoring my site using ...
  • 103
0 votes
1 answer
26 views

On android, keyboard comes up momentarily and then disappears when a user clicks the search field (likely due to triggering a js resize event)

Related to this: https://stackoverflow.com/questions/51493956/android-keyboard-appears-and-disappears-when-clicking-search-input We have some javascript that rearranges a couple elements in the page ...
2 votes
1 answer
92 views

How to remove a css file from an already-overridden definition?

I want to create a custom theme and remove a css file from diretory themes/stable/css/filter.caption.css from Stable theme. I found this file in stable.info.yml libraries-override: filter/caption: ...
user avatar
-1 votes
0 answers
49 views

Change value of rendered array in twig

Trying to modify a facet list item in my facets-item-list--links--bookmark.html.twig {{ kint(item.value)}} display a rendered array i would like to change the item.value['#title']['#value'] so that ...
  • 3,109
0 votes
2 answers
41 views

How do I check if TwigTweak is enabled before declaring a function in a template?

I am cretaing a theme which uses the twigtweak module to display some views/blocks in some of the templates. If a person enables the theme before enabling twigtweak module they get an error. For ...
-2 votes
0 answers
21 views

TypeError: when using a replace at item.value in facets-item-list--checkbox.html.twig

I have a facet with checkboxes. I tried to replace the css class of the input field with a peplace: <li{{ item.attributes }}>{{ item.value|replace({'facets-checkbox': 'uk-checkbox'})|raw }}</...
  • 465
0 votes
0 answers
22 views

Adding template suggestions for a view with display ID

I need to have suggestions for views to create dedicated template. Actually I've this in my .theme: function starter_d9_2022_theme_suggestions_views_view_alter(array &$suggestions, array $...
0 votes
3 answers
86 views

How to add some content every Nth comment?

My use is case is that I wish to show an advert every 3rd comment. The forum module added the comment field to the forum content type. So the field name is comment_forum. I have a block that contains ...
1 vote
1 answer
53 views

Why precisely the twig raw filter is unsecure?

Why precisely the twig raw filter is insecure in the drupal context? What would be an example of a potential threat ? And what need to be done on the ckeditor field format side to protect potential ...
  • 3,109
1 vote
1 answer
182 views

is there a twig filter to correct the HTML?

the slice filter on html code can generate invalid html that can cause in cascade JS errors {% set text = paragraph.field_verbatim_text.value %} {% if text|striptags|length > 300 %} {{ text|...
  • 3,109
-4 votes
1 answer
53 views

How do I render a radio inside a label?

The drulma theme has a form-element--type--radio.html.twig template file that is rendering the radio input and then the label. <div class="control js-form-item form-item js-form-type-radio ...
  • 1,385
0 votes
0 answers
94 views

Attribute Array to String Conversion Error

I'm getting this error now on most pages within a complex 9.5.3 site running PHP8.1: Array to string conversion in Drupal\Core\Template\AttributeArray->__toString() (line 77 of core/lib/Drupal/...
2 votes
1 answer
201 views

Why does “ Nesting level too deep - recursive dependency?” occur in a compiled template?

After upgrading from 9.4.8 to 9.5.3 a problem came up (see below) so when I add more than one image in articles media field node-image, I get a 500 error. PHP Fatal error: Nesting level too deep - ...
  • 109
0 votes
1 answer
61 views

Alter all webform fields

If we want to alter webform item e.g. add a colon : to a label of a specific field, we use this: $form['submitted']['my_form_component']['#title'] = $form['submitted']['my_form_component']['#title'] . ...
0 votes
0 answers
23 views

Twig template for field component of specific form [duplicate]

I'm using template hints to attempt to theme a specific part of a single form. I have a custom template for a views block (block--views-exposed-filter-block--search-custom-page-1.html.twig), but is it ...
  • 545
2 votes
1 answer
80 views

Is there a simple way to add a core themes css file to your custom theme?

Is there a way to declare a css dependency in a custom themes libraries.yml similar to adding core js dependencies? If I can avoid it, I'd rather not just copy a core themes css into my custom theme ...
0 votes
0 answers
25 views

Where to implement CSS previously implemented by CSS_editor now deprecated

Views with tables have a Flag that changes from Pending to Complete when the row is completed. The background of the entire row changes color depending upon the word. Working css_editor code (theme ...
  • 135
2 votes
1 answer
33 views

Testing equality of two variables - one is entity reference

I'm new to Drupal theming and twig, so apologies for asking a simple question, but it's driving me crazy. I can't find the solution. I'm trying to test the equality of field from a Custom content type ...
0 votes
1 answer
60 views

How to render fields with ->view() in a render array table?

I am building a table in my build function of a block and want to render formatted field values or entities with the ->view(); method in a cell of my table. As described here: https://www....
  • 195
2 votes
1 answer
236 views

Looping through child elements in Twig 2.10 without using if

Currently I need to loop through child elements in my Twig to render dynamic grids properly. I have achieved this by using code similar to this {% for key, child in element if key|first != '#' %} &...
1 vote
1 answer
63 views

How can I add term's vocabulary name as body class?

I already had following codes added, which adds term ID as body class. However, how can I change the ID to term's vocabulary name? For example: <body class="term-type-cameras"> /** *...
0 votes
0 answers
61 views

How can I print the link to the media file?

I have an image media type. I would like to display the image and the link to the file in the rendered Media. I don't want the image to be a link to the file. I couldn't find a link to the file field ...
  • 1
1 vote
1 answer
98 views

How to separate Twig array via batch [closed]

I'm trying to structure the output of a view into specific HTML for a carousel/slider I'm generating, basically I'm trying to turn a regular list of X people into groups, which I'm then dividing ...
1 vote
1 answer
95 views

How can I display no results text in a template?

I have added no results behaviour text to a view called Events which is a page. This template I am using has a twig called views-view--events--page_1.twig. I want to add the no results text to this ...
  • 137
0 votes
0 answers
31 views

For specific block use unique template file located in custom module's templates folder [duplicate]

Within my custom module 'footermenu' I would like to specify a template file for a specific menu block. I also want to locate the template file within the /templates folder of my 'footermenu' module. ...
1 vote
1 answer
164 views

How do you override a module's template from another module?

I'm trying to override an email template of the webform module. The project is headless so we don't have a custom theme, and we'd like to stick with the Adminimal contrib theme. However, we do have a ...
  • 111
0 votes
1 answer
32 views

Theming User Address Book Page

We are using drupal commerce2 on drupal 9, and I am trying to theming the address book tab (add some classes to layout and fields), /user/*/address-book. Unfortunately there isn't any twig template in ...
0 votes
1 answer
29 views

Add theme suggestion to a node depending on the menu it belongs to

I have a mega menu that displays child menu items when you click on a parent menu item in form of a drop-down menu. The thing is that, this menu, also displays cards as nodes and I want to add a theme ...
1 vote
1 answer
80 views

Provide theme suggestions for menu content items

For a mega menu, I'm trying to add theme suggestions to every parent menu item / menu link depending on the chosen view mode for that menu item. I'm aware of the ...
1 vote
1 answer
59 views

Is it possible to override a template from the module where the original is declared

I'd like, from within a single module, to have several 'api_field' template depending of the 'field_name' (including the default 'api-field.html.twig' ) Like api-field--country.html.twig, api-field--...
  • 353
0 votes
2 answers
342 views

How to display Media image with alt attribute in paragraph twig template

I'm trying to access alt attribute as in given example Get Media Image URL in Paragraphs Twig Template - Drupal 8 But there is an example how to access alt and title... That's easy, too. You should ...
0 votes
0 answers
28 views

Adding data-attributes in links override theme

In the classy theme of drupal I would like to override this code {% if links -%} {%- if heading -%} {%- if heading.level -%} <{{ heading.level }}{{ heading.attributes }}>{{ heading....
  • 1
1 vote
2 answers
167 views

How to use field value to set custom class and apply it to a html element in node.html.twig without using attributes and addClass()

I have tried to apply my custom class to an image tag I have set classes for it {% set imgClass = [ 'img-shape-' ~ (node.field_image_animation_shape.value|clean_class) ] %} and have ...
-2 votes
1 answer
207 views

How can I get the field value from preprocess_field?

I would like to get the content of the field with is formatted text to manipulate it a bit (strip from HTML tags and limit) and display it as another variable in twig. How can I get the value of the ...
0 votes
2 answers
92 views

How can I append a field to the body field?

I have a content type (Press releases) with three fields: field_date, field_location, and body. I am trying to create a template override for this content type based on this design. As you can see in ...
0 votes
1 answer
107 views

html.html.twig Template Name for content type

https://www.drupal.org/docs/theming-drupal/twig-in-drupal/twig-template-naming-conventions gives the example of html--node--[nodeid].html.twig for an individual node - what template name can I use for ...
  • 345
-3 votes
1 answer
58 views

How to display a block on the home page when the user is authenticated or anonymous?

I created two custom blocks. I want to display its two blocks only when the home page view is empty. I want the custom block with id 11 to be displayed for anonymous users. I want the custom block ...
0 votes
0 answers
72 views

Why is my css in my twig template getting ignored when I apply it to a newsletter issue and then email that newsletter to myself?

I have created a simplenews Newsletter issue called test1 newsletter. In the simplenews-newsletter-body--default.html.twig template file I use for the newsletter, I need to add some CSS styles. This ...
  • 13
0 votes
0 answers
64 views

how to get field image of a referenced entity in paragraph template

I made a paragraph with a referenced entity field to a content type called "tools" Actually I can get the title and body text like that : <h3>{{ content.field_tools_and_services.0['#...
0 votes
1 answer
188 views

How to get menu Attributes from a theme's preprocess function?

I am developing a theme and trying to send custom vars to a twig menu template (since it pulls data from config) and have a loop to add variables in preprocess: foreach($attributes as $attribute => ...
  • 293
0 votes
0 answers
240 views

How to use striptags twig function in a commerce product template?

For a client I need a wysiwyg field on my nodes and commerce products so they can add <em> and <span>&nbsp;</span> tags in their titles. I display this title_nbsp field value in ...
  • 732
0 votes
1 answer
72 views

Unable to install theme: '…' due to unmet module dependencies: '1'

I have a weird error with a custom theme (called uv_basic_theme). It ran well under Drupal 8, and now I've upgraded the site to Drupal 9. (9.4.4) After upgrade, the status report listed this error: 1 (...
-1 votes
1 answer
288 views

mime type ('text/html') is not supported stylesheet MIME type, and strict MIME checking is enabled [closed]

Im just trying to add Fontawesome to my new custom theme in libraries.yml but im getting: mime type ('text/html') is not supported stylesheet MIME type, and strict MIME checking is enabled. global-...
0 votes
0 answers
90 views

How do I remove the view container from Drupal 9 custom theme for a particular view

I am new to Drupal theme development and would like to know how to remove the view container divs that hold views-element-container, view and view-content. I tried to change the template file ...
0 votes
1 answer
37 views

Preprocessing twig templates

I currently have two templates, one of which is page.html.twig, which is the main page and I can preprocess with MYTHEME_preprocess_page(). MYTHEME_preprocess_page() affects all the other pages in ...
0 votes
1 answer
116 views

How to custom output a media paragraph from within a custom block?

I have a two-column custom block type that has two fields field_content_left and field_content_right which are entity reference revisions to allow the use of my other paragraph types. One of my ...

1
2 3 4 5
214