Questions tagged as ['theming']

Use it for questions about rendering or modifying the HTML markup produced by a module/theme.
Score: 0
Joehoe avatar
A specified library is missing
tr flag

On a custom theme "foobar" (based on Olivero) this error message occured. This custom theme is a copy of drupals 9.2.2 olivero's theme.

Drupal\Core\Asset\Exception\InvalidLibrariesExtendSpecificationException: The specified library "foobar/cke-dialog" does not exist. in Drupal\Core\Asset\LibraryDiscoveryCollector->applyLibrariesExtend() (line 154 of core/lib/Drupal/Core/Asset/LibraryDiscoveryCollecto ...

Score: 2
jhnc avatar
correct way to access node-revision change property in twig
cn flag

I have a Drupal 8.9.17 website. My theme (based on Garland) includes in templates/page.html.twig:

{% if node %}
[...]
Last updated {{ node.changed.value|format_date('custom', 'D M d Y') }}
[...]
{% endif %}

This displays the property when viewing nodes at: /node/<nid>

However, when attempting to view revisions at /node/<nid>/revisions/<vid>/view, format_date() fails with "null times ...

Score: 0
deelite avatar
"block_name" not found
cn flag

I installed the Twig Tweak module.

{{ drupal_block('block_name') }}

doesn't work. In Drupal logs I get the error

The "block_name" was not found

"block_name" I get from the config url of the block config page

admin/structure/block/manage/block_name?destination=/de/admin/structure/block

Do I do anything wrong?

Score: 0
Interlated avatar
How do I debug overridden twig templates?
km flag

How do I debug the template overrides. The debugger stops on page.html.twig but doesn't stop on sub templates such as

web/themes/custom/localtheme/templates/field--paragraph--field-pbcrossfade-image--crossfade-banner.html.twig

The page.html.twig breaks here

enter image description here

The debugger does not break in the sub template.

enter image description here

Score: 0
hotwebmatter avatar
Template preprocess to generate Font Awesome markup for menu links
nr flag

In Drupal 9, I need the ability to prepend Font Awesome icons to menu links.

I have attached Font Awesome 5 JS and CSS assets to my theme via *.libraries.yml.

If I open a menu link in the DOM inspector and edit the markup of a link from this:

<ul class="clearfix nav">
  <li class="nav-item">
    <a href="#comments" class="nav-link nav-link-comments">Comments</a>
  </li>
&l ...
Score: 0
Interlated avatar
How do you add a CSS class if the default field value is chosen?
km flag

How do you identify that the default taxonomy field choice has been chosen?

Solution consists of a taxonomy list. If the default is chosen the title in the display should be hidden.

Using views to display the list.

Score: 0
Dorian Winterfeld avatar
What is the correct way to load a JavaScript library?
ae flag

I am trying to display form data as a line chart. I am running Drupal 9 in Lando. I am using Charts 5.0.x w/ the Highcharts submodule. I installed the Highcharts JS library using composer. This is the relevant code.

.libraries.yml

highcharts:
  js:
    /libraries/highcharts/highcharts.js: {  }
  dependencies:
    - core/jquery

.module

function stats_degrees_theme() {
  return [
    'mychart_templ ...
Score: 0
Using Twig in global custom text to check for a specific content type
in flag

I am filtering for two content types to display in a view: Artwork Page and Cover Page. I want to change the HTML markup for Cover Page.

I have researched and tried many field names for Content Type, but with none of them I get what I am trying to achieve. In this instance, the replacement pattern for Content Type is {{ type }}; using it doesn't work. I've tried both the machine name (cover_page) an ...

Score: 0
Twig template for just one page in a view
br flag

I have a Drupal view (Product Section) where I have a master view. This is the view I'm currently using for Computers, Cell Phone, and other pages I am still creating.

screenshot

I also have a Product Shop page, which is almost like the parent page. For this page, the path is /products, for Computers is /products/computers, and so forth.

In my theme folder, inside of the templates folder, I created a page--produc ...

Score: 0
Unable to check if variable is empty in views twig
in flag
Lub

I am trying to overwrite views-view-unformatted.html.twig file and want to check if title variable is empty or not, but whatever I do, it always acts just like it is not empty.

I know title variable is an object, I tried dpm() it but no modifiers work in checking if it is empty.

My code:

{#
/**
 * @file
 * Default theme implementation to display a view of unformatted rows.
 *
 * Available variables:
 ...
Score: 2
Sarah C avatar
How to verify if a custom logo is used?
za flag

How can I check whether the site is using the default theme logo or a custom logo?

When I use the Twig debug tools to dump the site_logo variable, I only get the path of the logo, which doesn't tell me if that is the default theme logo.

Score: 3
Can we add custom CSS class in \Drupal::messenger()->addStatus()?
cn flag

I did some research regarding adding custom CSS classes in the message but could not find the actual solution.

As per Drupal 9 documentation:

\Drupal::messenger()->addMessage(t($message));

public function addMessage($message, $type = self::TYPE_STATUS, $repeat = FALSE);

I don't find the option to add CSS class. On the frontend, I would like to add custom CSS class custom-messages--status in the outp ...

Score: 0
Monster971 avatar
How to make a vertical menu properly?
id flag

Good morning all,

Today I would like to ask a simple question about the menus. How do you make a clean sidebar that takes up the entire length of the page? In general, the themes offer only natively horizontal menus that occupy the entire width.

To have a sidebar, you must put the menu in a block side position and make the necessary adjustments with CSS?

Score: 0
stckvrw avatar
How to receive menu items in Twig template as array/object?
gb flag

I need to receive (for example by menu machine name) and operate menu items data to use it in Drupal Twig template like:

<ul>
{% for item in items %}
    <li><a href="{{ item.url }}">{{ item.title }}</a></li>
{% endfor %}
</ul>

But I can't find an information on how to do that.

The only thing I've found is like

{% import _self as menus %}
{{ menus.menu_links(items ...
Score: 1
Giuseppe avatar
How can I customize the 403 page for specific routes?
br flag

On a D9 site, with an existing custom 403 page twig. I've been requested to show a different, variable, message from the "standard one" for a couple of specific routes.

I've tried with theme_preprocess_page__403(&$variables) but I couldn't determine the original route.

E.g. using \Drupal::routeMatch()->getRouteName() I got system.403 instead of the route name I need to check. I've checked solution ...

Score: 1
Thirsty Six avatar
Advagg with S3fs relative url() references inside of CSS files - broken image URL
gs flag

Background Images Paths are Changed when CSS Aggregation is On

s3fs module with AdvAgg to store CSS/JS aggregates on the S3 stream wrapper

Without Aggregation (Works well). fetch from domain base url.

background-image: url(/themes/THEME/images/test.jpg);

Src of the image in CSS, which is pointing to the CNAME for S3

With Aggregation isn't working. Because, my CNAME is different from my DOMAIN name.

 ...
Score: 1
Add additional taxonomy term fields to an exposed filter form
in flag

Brief: How to add a custom field from a taxonomy term into a View's exposed filter form?

Specific: I have an image field added to taxonomy terms that I want to add to the exposed filter form along with the radio button and the TID's name (default is only radio + name), themed with Twig template.

More words:
Hello,
I'd like to modify an exposed Views filter form to include the rendered image field fro ...

Score: 0
JonMcL avatar
Why is the region content already rendered as markup?
us flag

I'm attempting to craft some custom layout HTML in one region of my theme (uswds_base, but this doesn't appear to be theme specific). The content of a typical region.html.twig file is like the following.

{% if content %}
  <div{{ attributes.addClass(classes) }}>
    {{ content }}
  </div>
{% endif %}

Why is {{ content }} already rendered as a markup string in a region template? I'd like ...

Score: -2
Rick avatar
Unable to pull image inside twig file
us flag

I am trying to show image via view twig file and below is my lin eof code:

<img width="220" height="112" src="{{ file_url(content.field_thumbnail_new[key]['#item'].entity.uri.value )}}" alt="{{ item.alt }}" />

When inspecting, I see the below:

enter image description here

any help on how this can be fixed pls?! I am using D9.

Score: 1
Loopy avatar
What is the new methodology for Form Pre-Render in order to utilize TrustedCallbackInterface
cn flag

We are upgrading our sites one at a time from Drupal 8 to Drupal 9 and there is one line of code in our custom theme that is the last of our problems.

We get the following error on View that uses an exposed filter:

Drupal\Core\Security\UntrustedCallbackException: Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous fu ...
Score: 1
Matoeil avatar
is it possible to deactive twig cache for a single theme custom template?
za flag

i am having a custom template for rendering a medialink url from a paragraph media entity ref field. In production with twig cache activated, modifiying the media attached file , does not update the content making reference to that media, unless the render cache is emptied.

paragraph--link-media.html.twig

{% set classes = [
  'paragraph',
  'paragraph-link-media',
] %}
{% set link_classes = [] %}
{% s ...
Score: 0
How can I print the Layout builder in a node twig template?
eg flag

After enabling Layout builder for Page content. I can see in Manage fields, a new field called layout_builder__layout. I want to print this inside node--page twig template. This should work but it does not. {{ content.layout_builder__layout }}. Printing all the content does display it like this {{ content }} How can I print only the layout builder?

Score: 1
Henk schipper avatar
Custom admin theme showing links in backend from frontend
us flag

So im new to drupal and i'm learning on how to use custom theme's by reading theming drupal. There is a topic about sub theming and I thought it was interesting to make a sub theme from the default admin theme seven. So I just follow the steps adding all the regions also.

So my frontend is having this as content (default stuff); frontend content

But the problem is, it is also showing it in the backend;

backend content

While i didnt ch ...

Score: 0
Using template variations from the modules folder
lc flag

I have the usual theming solution for a custom entity:

function module_theme($existing, $type, $theme, $path) {
  return [
    'customentity' => [
      'render element' => 'elements',
      'template' => 'customentity',
    ],
  ];
}

function template_preprocess_customentity(array &$variables) {
  $variables['content'] = [];
  ...
}

function module_theme_suggestions_customentity_alt ...
Score: 1
Ex0r avatar
Making custom template & variables in module
cn flag

I am working with D8, and don't usually do themeing, so I am stuck on a problem.

I have a custom route in a custom module that calls a method checkinConfirmation() on a controller.

Inside that controller, I have this:

public function checkinConfirmation() {
  $output['items'] = [
    '#type' => 'fieldset',
    '#title' => t('Checked in items'),
  ];
  $output['items']['name'] = [
    '#prefix' =&gt ...
Score: 0
Private file not being displayed on Twig template
ru flag

I am trying to get an image from the private folder to display on a printer-friendly Twig template page. The private folder is inaccessible to browsers and the only display method I know of is to load the image and convert it to Base64 and pass the Base64 characters into the 'src' attribute of an 'img' element.

My controller code looks something like this:

class PrinterFriendlyController extends Contr ...
Score: 0
Matoeil avatar
Pass current langage to twig on custom blocks
za flag

my custom module block, with supposely no cache

<?php

namespace Drupal\amu_social_icon\Plugin\Block;

use Drupal\Core\Block\BlockBase;

/**
 * Provides a 'Icon' Block
 *
 * @Block(
 *   id = "amu_social_icon_block",
 *   admin_label = @Translation("Social Icon block"),
 * )
 */
class IconBlock extends BlockBase {

  /**
   * {@inheritdoc}
   */
  public function build() {
    $config = \Drupal: ...
Score: 1
hga77 avatar
Somehow subscribe/react to addMessage
cn flag

I'm trying to find an event that I can subscribe to for the method addMessage.

I need to trigger some code everytime a status message is added. On reacting to this event, I need to send a variable from php to JS. I could not find an event to subscribe to so instead I used a preprocess, below.

<?php
function mymodule_preprocess_status_messages(&$variables) {
  $variables['#attached']['drupalSettin ...
Score: -1
Amr.Mohammad87 avatar
undefined drupal_add_js function inside themename_preprocess_page
cn flag

I wanted to use javascript to delete an option from the list of options in case the user is not an administrator and I searched and found this code inside a post and I used it inside the project's themes->mythemename->mythemename.theme file, but that didn't work and I have several problems I want to know how to solve, as I searched a lot I did not find a solution

function mythemename_preproce ...
Score: -1
How can I make Barrio SASS gulpfile coninue watching for changes
eg flag

When running gulp. It runs and compiles SASS one time. How can I adjust the watch so that it continues watching for changes. Do I need to add usePolling: true or usegulp.series. I am following the directions exactly from the Bootstrap 4 SASS - Barrio Starter Kit

My setup: drupal core 9.1.10 bootstrap_barrio 8.x-4.33 bootstrap_sass 8.x-1.13 node v12.22.1 npm 6.14.12 gulp CLI version: 2.3.0 gulp Local vers ...