Skip to main content

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
0 votes
1 answer
111 views

How to make it so theme function isn't used when editing a node with layout builder

I have the following two functions in my .theme file that I'm using to gleam various bits of information from both the path alias and internal URL of the page being viewed. They are: function ...
fallenturtle's user avatar
1 vote
1 answer
71 views

How can I render comment pager on the top and the bottom of the comments portion of the page

When comments are numerous on a node and you have a high comments per page setting, you have to scroll a lot to get to the pager. My users have requested pager at top as well as bottom of the comments ...
aharown07's user avatar
  • 392
0 votes
1 answer
299 views

When iterating over multi-value fields is it considered best practice to override the field template vs loop over the var in node or block template? [duplicate]

I have a link field that allows multiple (3 max) values on a custom block for which I'm using a twig template. I want to iterate over the values using a for loop. I got this to work the way I wanted ...
user92354's user avatar
0 votes
1 answer
816 views

How to get value from object in twig template file? [duplicate]

I can print the result object by {{ dump(item.value['#result']) }} in theme item-list--search-results.html.twig template file. I want to print the body field value("body"=>"value&...
Ramalingam Perumal's user avatar
1 vote
1 answer
284 views

Barrio Theme 5.5.10 Main Menu submenu does not output list items

I need help with the Barrio Theme submenus. I upgraded our site to 5.5.10 to discover the menu has stopped working. In my attempt to figure this out, I recreated a test site locally and installed a ...
Crystal's user avatar
  • 13
-3 votes
1 answer
38 views

Avoid adding custom CSS to a node editing form?

Situation custom module adding styles don't add styles to node editing form How to avoid adding the style to the editing forms? function crossfade_page_attachments(array &$page) { $page['#...
Interlated's user avatar
  • 1,423
-3 votes
1 answer
479 views

Get MenuLinkContent object values [closed]

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 ...
New Dev's user avatar
0 votes
3 answers
160 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 ...
LBRTYCAT's user avatar
0 votes
1 answer
491 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 ...
Patrick Man's user avatar
2 votes
1 answer
172 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
0 votes
2 answers
235 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 ...
Jay Williams's user avatar
1 vote
1 answer
399 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 $...
WebmasterPF's user avatar
0 votes
3 answers
135 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 ...
gMaximus's user avatar
1 vote
1 answer
481 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 ...
Matoeil's user avatar
  • 3,443
1 vote
1 answer
556 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|...
Matoeil's user avatar
  • 3,443
-4 votes
1 answer
273 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 ...
Interlated's user avatar
  • 1,423
0 votes
1 answer
628 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/...
Rob Carr's user avatar
2 votes
1 answer
703 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 - ...
isin's user avatar
  • 109
0 votes
1 answer
110 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'] . ...
user3108268's user avatar
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 ...
Sam's user avatar
  • 623
3 votes
1 answer
393 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 ...
sidgrafix's user avatar
0 votes
0 answers
31 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 ...
DStrider's user avatar
  • 135
2 votes
1 answer
38 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 ...
Christopher Lambert's user avatar
0 votes
1 answer
340 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....
Michiel's user avatar
  • 305
3 votes
1 answer
1k 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 != '#' %} &...
Lurnobis's user avatar
1 vote
1 answer
86 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"> /** *...
Kingto Wong's user avatar
0 votes
0 answers
343 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 ...
Rico's user avatar
  • 1
1 vote
1 answer
247 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 ...
Andrew Morris's user avatar
1 vote
1 answer
382 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 ...
MrFox's user avatar
  • 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. ...
websoft's user avatar
2 votes
2 answers
1k 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 ...
nstCactus's user avatar
  • 152
0 votes
1 answer
116 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 ...
Samuran Wong's user avatar
0 votes
1 answer
37 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 ...
Alejandro's user avatar
1 vote
1 answer
422 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 ...
Alejandro's user avatar
1 vote
1 answer
117 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--...
Thony's user avatar
  • 373
2 votes
2 answers
2k 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 ...
Vitaliy K's user avatar
  • 129
0 votes
0 answers
45 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....
chtouk's user avatar
  • 101
1 vote
2 answers
463 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 ...
Vitaliy K's user avatar
  • 129
-2 votes
1 answer
1k 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 ...
user108425's user avatar
0 votes
2 answers
135 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 ...
Sam Bara's user avatar
0 votes
1 answer
279 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 ...
Juc1's user avatar
  • 369
-3 votes
1 answer
238 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 ...
francky's user avatar
0 votes
0 answers
293 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 ...
Diamoniner12345's user avatar
0 votes
0 answers
179 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['#...
johndoe555's user avatar
0 votes
1 answer
479 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 => ...
adam_bear's user avatar
  • 293
0 votes
0 answers
668 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 ...
MacSim's user avatar
  • 804
0 votes
1 answer
295 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 (...
Georg Jähnig's user avatar
-1 votes
1 answer
512 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-...
Felipe de Jesús's user avatar
0 votes
1 answer
107 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 ...
murko233's user avatar
0 votes
1 answer
428 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 ...
ACanadianCoder's user avatar