Questions tagged [theming]

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

2,418 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4
votes
1answer
543 views

How to pass a field value as contextual filter argument using Twig Tweak drupal_view?

In Drupal 8, I'm using Twig Tweak to embed a view. I have a contextual filter set to one of the node's fields, field_project_id. If I use a literal for the third argument, it works. If I try to ...
4
votes
1answer
203 views

Twig cache files on load-balanced setup

The Twig cache key (twig_cache_prefix) is based the modify timestamp of the Twig template file and a randomly generated key. This gives a problem with a load-balanced Drupal setup where every host has ...
4
votes
2answers
565 views

Get paragraph delta/weight in template

I have defined a paragraph type that has a text field and an image field. At the moment the twig template is something like this <div class='paragraph_wrapper'> <div class='text-container'&...
4
votes
0answers
803 views

Trying to set a twig global variable for a function

I have a Twig function in my theme that sets a random ID. The function works well if I include the entire function within any given template and then render the variable for that {{ randomID }} in the ...
4
votes
0answers
589 views

Theming links in blocks using twig templates

I have a block for the language switcher. I want to override the links in it. I can override a specific language switcher block's markup, and I can override the links markup in all language switcher ...
4
votes
1answer
112 views

Can composer-dependent PHP libraries be used with the Libraries API?

I'm trying to include a PHP library called Geocod.io in my custom module. I am also trying to use the Libraries API. So far I have: Downloaded geocod.io to sites/all/libraries composer install'ed in ...
4
votes
3answers
898 views

Get field_collection values in field template

I have installed field_collection and have a collection called field_contact, each entry of which has a field called field_contact_url I'm trying to customise the display of that field by overriding ...
4
votes
2answers
1k views

Adding new rows on a draggable table via jquery

I have a draggable table with preloaded "new items" - sorta like the Power Edit feature of the menu_editor module. Everything works perfect. However, I want to have a button that adds a new row via ...
4
votes
1answer
220 views

Why Calling the theme path in a multinlingual site adds a language prefix?

In my template whenever I call the path to my theme in a particular language it adds a language suffix dir like mysite.com/fr/sites/all/themes/mytheme while I'm expecting a path without a prefix (e.g. ...
3
votes
0answers
305 views

How to change the title of a modal window?

I have a link that displays a modal window. The link redirects to a page view. When I click on it, it is marked in the title of the modal window Array. How to customize the title ? <?php ...
3
votes
1answer
66 views

How do I capture a page as HTML?

I have a controller that generates a custom 500 page. I have set up a route at the path: '/500'. I would like to capture this as HTML and save as a static file, so that I don't need to bootstrap ...
3
votes
1answer
161 views

How to render a @FormElement in Views area plugin

I am doing a custom plugin area for displaying some data in a views footer (Drupal 8). I do something about just like this : Create a custom area plugin The only point is, instead of #markup in the ...
3
votes
1answer
828 views

Manipulating Theme Suggestion Priorities

I'm adding in some theme suggestions using mytheme_theme_suggestions_alter(), when certain criteria is met. My issue is, for some reason these additional theme suggestions are appearing at the top of ...
3
votes
1answer
91 views

Display comments according to the users roles

I try to create various tabs for my nodes, which show a specific field and the comments of the users according to their roles : I would like that these tabs are pages, and not in Javascript tabs. ...
3
votes
1answer
104 views

“Initial Menu Level” config in Block Layout not working

Using Drupal 8... Goal There are 2 regions in the header. The top region holds the Level 1 menu links while the bottom region holds the Level 2 menu links (or child links of the top regions). What ...
3
votes
1answer
836 views

Override form.html.twig into module

i need to override a form.html.twig in my custom module. i used hook_theme_suggestions_alter in my .theme file to add new suggestions. function MY_THEME_theme_suggestions_alter(array &$...
3
votes
2answers
406 views

Customize menu local task links

I am looking for a way to customize 'edit', 'view', 'delete' links. I use bootstrap theme, but i use bootstrap v4 styles for it. I want to add 'nav-link' class to each link. And find a way to ...
3
votes
0answers
2k views

What Twig variable can i use to view Page Title or Taxonomy Name for a Taxonomy Type page

In Drupal 8 I need a way to get the Current pages title or Taxonomy name/ID. In the template taxonomy-term.html.twig the variable works: {{ term.id }} I need the variable to work in page.html.twig ...
3
votes
2answers
342 views

Change icon class in “Add to cart” button

I am using Drupal 7, Ubercart, and Bootstrap. The default Add to cart button looks like this: <button id="edit-submit-270" class="node-add-to-cart btn btn-success form-submit" value="Add to cart" ...
3
votes
1answer
158 views

Why is 'render element' sometime 'element' and sometime 'elements'?

I notice in Drupal source code, in core modules hook_theme(), some places are 'render element' => 'element' and some places are 'render element' => 'elements' (plural). Why? Even the render ...
3
votes
0answers
1k views

8 - Firefox loads JS before CSS, causing flash of unstyled content

My Drupal 8 site will load fine in Chrome and IE, because they both load my CSS before my JS when I look at the Network tab in the console. But when on Firefox, it will load the JS before the CSS. ...
3
votes
2answers
513 views

How to remove markup from file field

I have added a file field in views and when displaying it has some markup like this <div id="file-218" class="file file-image file-image-jpeg contextual-links-region"> <a href="#"> ...
3
votes
1answer
245 views

How can can I get theme callback to work for an error page?

I've created a custom error handler for 404 errors (page not found). I've set up Home » Administration » Configuration » System » Error Pages for 404 errors to point to http://example.com/...
3
votes
0answers
187 views

Disable form altering for admin pages on Bootstrap 3

My default theme is Bootstrap but I use Shiny theme as admin theme. Bootstrap theme alters the forms and fields. And I use Hierarchical Select module, there is a dropbox for multiselection and the ...
3
votes
2answers
228 views

What to name field collection theme file?

There are several articles here that address theming field collections but none that specifically cover the naming conventions required to actually get them recognized by Drupal. field--field-field-...
3
votes
1answer
146 views

Override and add a link to a themed table

Using a custom module, I'm trying to add "Schedule" links to each of the rows of the table on node/%nid/revisions, but can't seem to figure it out. Do I have to override the entire function ...
3
votes
1answer
223 views

Removing the active language

I'm having some trouble with removing the active language from the Language Switcher Dropdown module. I'm trying to override theme_languageicons_icon() with the following code, but it doesn't seem to ...
3
votes
1answer
311 views

Move drag and drop handle to other side

I want to move the drag and drop handle to the other side of a form, to the same location as the row weight selections. I am talking about the tabledrag handles, as shown below: I am using ...
3
votes
1answer
407 views

Templating JSON

Is there a Drupal way to template the results of ajax query that returns JSON. The JSON is is being returned to some php module code. If there is not a Drupal way I was thinking of using something ...
3
votes
2answers
282 views

drupal_find_theme_functions called on every page - is our theme registry being rebuilt?

Our new D7 site was running very slowly so I did some profiling with devel/xhprof and found that D7 was doing millions of preg_grep function calls within drupal_find_theme_functions() in theme.inc. ...
3
votes
1answer
799 views

How to change the View Mode based on theme?

I am using the ThemeKey module to change the theme for mobile users. I have a custom View Mode called Mobile to display different content. I would like to have when my mobile theme is loaded for the ...
3
votes
1answer
442 views

Select an Image style depending on external/dynamic factors (theme region or other field content)

I have a Bean (bundle that generates blocks) which I display in one of 2 different theme regions. Either in the header, or the footer. This Bean contains an Imagefield, which is rendered through an ...
2
votes
0answers
68 views

How can I use Html::getUniqueID in Twig

The Drupal Twig |clean_id filter calls HTML::getId, which is inferior because accessibility tests fail if your ID appears twice, for example, when the template is placed twice on a page. In the vast ...
2
votes
1answer
49 views

Twig whitespace controls have no effect on fields

I am trying to iterate over a Paragraph field and apply a comma after each Paragraph item. In the field template that outputs the Paragraph, I am trying: {%- for item in items %} {{ item.content }}...
2
votes
0answers
77 views

Contextual links in block disabled when using Twig Tweak and UUID

In my taxonomy-term--NAME.html.twig I use a reference field to load a 'block_content'. {% for item in term.field_blocks %} {% set uuid = item.entity.uuid.value %} {{ drupal_block('block_content:'...
2
votes
1answer
59 views

Avoid random number cached in preprocess hook

I have a random set of images that appear on the homepage which needs to show each time the page is refreshed. My holding page was doing this comfortably in PHP, but since building the whole site and ...
2
votes
1answer
100 views

Adding Price Attributes

I am searching how to add price values to existing product attributes in Drupal Commerce 2.X For Example: T-shirt price = $10.00 A product variation/color = Red = +$2.00 A product variation/size = ...
2
votes
0answers
54 views

What's the difference between adding a template and overriding a template, from a custom module?

I found a paragraph in the documentation about using template files in a custom module. This way can be even used to override a template like I did here. However, I am wondering if this is the ...
2
votes
0answers
46 views

How to change the pagination position

I have created a custom block using Entity Query with pagination to get the data and everything works fine with $render[] = [ '#type' => 'pager', ]; But I can find a way to change the position ...
2
votes
0answers
52 views

Global fields for nodes and blocks

I am trying to move the site from WordPress to Drupal 8, but there is one very unpleasant problem that I have been trying to solve for several days. I really hope that you will help me find the right ...
2
votes
0answers
72 views

Adding an Attribute to a Script Tag Before Src

I'm working with CloudFlare and have identified a script that needs the data-cfasync=“false” attribute applied so CF doesn't touch it. This script is defined in a library in a custom module. my-...
2
votes
1answer
203 views

Changing Twig template of form items through the theme

I have a block, which renders out a form using code that looks like this: {{ attribute(form.facets, 'filter_' ~ filter.name) }} I'd like to amend the markup and CSS classes for the various elements ...
2
votes
1answer
340 views

How to check in Twig file whether node has a field?

In my twig file i try to override the field. In the {% if %} clause I need to check whether a field has particular value, if yes then assign the value as a class. {% for item in items %} {% if ...
2
votes
0answers
28 views

External CSS file is not being loaded

I added an external CSS to my theme. When I look at the source code the external file is not being rendered. In my html.tpl.php file I have: <?php print $styles; ?> In my template.php. file ...
2
votes
1answer
41 views

Variable passed into a preprocess function has incorrect data or or an unexpected format

I wanted to change some of the forum’s topic's preprocessing. So I copied template_preprocess_forums() into a custom module (myModule), and renamed the function myModule_preprocess_forums(). I get an ...
2
votes
0answers
136 views

How to define CSS for Custom Display Suite Layout

I have added a custom layout for Display Suite on Drupal 8. Everything is working except the CSS for the custom layout is not working. This is my layout in my theme folder: mytheme.layouts.yml ...
2
votes
0answers
645 views

Add odd and even to field--item with twig template

I'm trying to add "odd" and "even" to an image field (which contain multiple images) theming each item : {% for item in items %} {% set zebra = cycle(['odd', 'even'], loop.index0) %} {% endfor %} {...
2
votes
0answers
149 views

Can't make sense of the CSS loading order

I want bootstrap.css to load first, because it's breaking all of my styles. Yet, no matter what settings I use in my module, it always loads last. Every CSS file from a library in my theme loads ...
2
votes
0answers
89 views

Create full page custom module

I would like to create a full page with a custom module. I mean a page that should not reside within the larger Drupal page. How can I achieve this? This is the code I am using. mymodule.module ...
2
votes
0answers
354 views

Drupal 8, Issues on theme a views block

I´m not able to theme a views block. I have found a lot of tutorials on how to rename the twig file, but i´m sure that i´m doing anything wrong with filename. I use the views-view.html.twig and i ...