The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
1answer
62 views

How can I add folders to my template directory and have Twig find them?

I was listening to a Drupal Developer on youtube and one of the suggestions he has, is that when you go into a template folder, create some subdirectories for easier management, like this: Templates -...
0
votes
1answer
70 views

How to print the URL path of a referenced node using paragraphs?

I'm trying to print out the url path of a node from a referenced entity paragraph field in my twig template however have not had any success so far. I have tried various common twig functions but with ...
0
votes
1answer
116 views

How to show contextual links / quick edit links for blocks

I'm building a Drupal 8 template/theme from scratch, and it is not showing the contextual editing options for my blocks when I view a site page. I.E., the little circles that are clicked to see ...
0
votes
1answer
27 views

Adding a script to certain pages

I am trying to add a script code on all but few pages. I tried the following code on the template.php bfile, but it doesn't work. function THEME_preprocess_page(&$variables) { if (isset($...
0
votes
1answer
81 views

Is there a better way to style fields?

I'm learning twig and using it to format and style my fields. The problem I am running into is that I need to create a new twig template for each individual field. In the example picture, I have ...
0
votes
1answer
33 views

How to print the URL of a title field?

I'm trying to print out the url path from the title in my twig template however I haven't been successful so far. Printing out the title containing the link works fine using: {{content.title}} ...
0
votes
1answer
40 views

How to create unique banner for each node and views page?

What I am trying to achieve: I want the unique banner image for each node and the views page, where the site administrator can simply upload the image and description to upload the banner for each ...
1
vote
1answer
34 views

Is the homepage considered in_active_trail?

I'm learning Drupal 8, so still very new to it. I'm working on customizing the main menu. I've been able to add Twitter Bootstrap to my custom theme. I've made a custom menu--main.html.twig file. I'...
0
votes
0answers
104 views

Kint function not working for me at twig template

I have enabled devel module and also enabled devel kint . From configuration section (development/devel) , I select kint as Variables Dumper. I also enable twig debug mode. But {{ kint() }} not ...
-3
votes
1answer
195 views

Use a Twig filter to resize / crop images in templates [closed]

I want to use a twig filter to resize/crop images in Drupal 8 templates for responsive images, I know I can generate responsive images with Image Style and Responsive Image styles, but that requires ...
0
votes
1answer
69 views

When I going to Disable Twig template cache , Fatal error

When I going to Disable Twig template cache , Fatal error . i.e The website encountered an unexpected error. Please try again later. Error: Unsupported operand types in Drupal\Core\Template\...
0
votes
0answers
22 views

get fields from a view into twig from a custom display style

So I created a custom display style following a tutorial and enabled fields to be used. I can't, however, figure out what the variables on the twig file should be to display the fields I want. MY ...
0
votes
1answer
29 views

Extending a base template file such as field.html.twig renders no results?

So I have a custom content entity that has the typical attributes. Name, Author, Creation Date, ect. In the 'view' tab of this content entity, it displays said name, author, ect. When I hover over ...
2
votes
0answers
109 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 ...
0
votes
0answers
37 views

Why is my custom twig template not being selected by Drupal?

So I have a custom module that has boilerplate template code inside it. No problem there. So I following the Drupal Docs which says to create a service.yml file and turn debug on and caches off. Done. ...
1
vote
1answer
46 views

Wrong User Image Display - Weird Twig Cache?

I'm having a weird issue with incorrect user images being displayed and it seems to be a caching issue or perhaps I am passing the user image incorrectly to my template. Problem: If I login to a ...
0
votes
1answer
70 views

Add target blank to an image link

How do I add target='blank' to a href in a Drupal 8 custom module? Below I have the image being wrapped by the uri. I don't know how to add target='blank' $element[$delta] = array( '#theme' ...
0
votes
0answers
23 views

trying to insert a view inside a view using twig tweak module

I am trying to insert a view inside a view but struggling a bit I have a view called My Class with all my fields in it, this works fine. I have a view with a contextual filter called Students Block,...
0
votes
0answers
40 views

Get input label on input.html.twig file

I'm working on an input.html.twig file. I need the label name of the input for class and other reasons, but for some reason, I can't figure out how to grab it. I thought it would be part of the twig ...
1
vote
1answer
94 views

Passing data from outer preprocess to inner template

I have two templates: - a child that is printing each item in a list; - and a parent that calls it there is also an intermediate Field template that is not involved. The parent has preprocess access ...
0
votes
0answers
40 views

How to get translated term name from TID in views field template?

For a complex view, I need to alter the output of a localized term field: instead of putting out the TID of the term, I would like to render the localized term name. Does someone know how to alter the ...
0
votes
1answer
19 views

Only display profile edit button on personal profile page

I'm using the profile module and am trying to display a profile edit button on your personal profile page. my profile.html.twig: <div class="m-section__content a-container"> {% if ...
0
votes
0answers
45 views

Content type fields list on the page.html.twig template

I have an HTML theme that I am converting to a theme in Drupal 8.7.0. I have created content type Hero content. Then I created fields inside: title body image (there are multiple images) offer(text) ...
0
votes
0answers
9 views

Drupal link value is showing the entity [duplicate]

The link field shows uri:"internal:"... and uri:"entity:" as a prefix in the field link URI. how can i fix that ? Thats how i get my fields uri value. {{ paragraph.field_stage_element_hp_link.uri....
0
votes
0answers
111 views

Loop Paragraph types with all values in field--field-page-detail-paragraph.html.twig

I have two paragraph types called First Type & Second Type and added Image & Text fields on it separately. I have created the basic page & added the two above paragraphs(First Type & ...
0
votes
1answer
21 views

Search info_split is empty

I need to customize the search results of a drupal 8 (8.7.0 currently) page a bit and need the node_type for this. According to search-result.html.twig, this should be stored in info_split.type, but ...
0
votes
1answer
197 views

Adding a custom data-attribute to a field in Views

In a view I need to add a custom data-attribute to the row output (just like classes are added). Simply rewriting the output doesn't work because XSS attribute filtering strips the attribute. How can ...
0
votes
0answers
50 views

Exporting content translation to similar server

I have 2 instances of the same site built using Drupal. Both need to be translated, and most of the work of the translation has been done on site A and we need to take the translations from site A to ...
0
votes
0answers
33 views

How does a custom module architecture work?

I am a beginner with D8 and I need to create a module with a custom form. I created the module and created the form. I also created a custom block in order to render the form (the plugin block and the ...
0
votes
1answer
48 views

Media images link to their own image

I have inherited a site which had no image management. Instead each image field required you to upload an image instead of reuse an existing one. I enabled Media Browser and updated to 8.7. I am also ...
0
votes
1answer
102 views

Rewriting image output in views: how to provide replacement pattern inside twig tag?

In views I want to rewrite output of image field by using twig function drupal_image (see module Twig Tweak). When I provide the image path directly, this code works: {{ drupal_image('public://...
2
votes
1answer
193 views

Adding a line break or space in TWIG

I'm trying to configure email confirmations that are sent out by one of our web forms. At the moment they are appearing without line breaks but I want to be able to have line breaks between certain ...
2
votes
1answer
57 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 }}...
1
vote
0answers
51 views

Why do I get “Warning: Division by zero in __TwigTemplate”? [closed]

I created the connectedFilters.js file in /themes/custom/module/js/ with the following code. (function ($, Drupal) { Drupal.behaviors.connectedFiltersBehavior = { attach: function (...
0
votes
0answers
27 views

How do I get the default comment form in the content type template?

I have created the comment field in the content type. How can I render the comment form using a specific content type template in Drupal 8?
1
vote
1answer
127 views

Understanding page-title.html.twig and/vs field--node--title.html.twig

This question is based on the desire to have only one wrapping tag around the title value. (I am utilizing the block system to render the page/node title) Both of the templates utilize some sort of ...
0
votes
1answer
356 views

How to display a link field with its link text in a twig template

A content type includes a link field link that accepts Link text. A user inputs the URL /target with the Link text "Go to target". How do I get twig to generate `<a href="/target">Go to ...
0
votes
1answer
42 views

How to retrieve the link and description in a custom file field twig template

I have a field field_file. I've created a template field--field_file.html.twig. How can I access the link, description (and attributes and icon ) separately in this file? I have: {% for item in ...
0
votes
1answer
27 views

Putting footer region under body tag

I'm fairly new to drupal and this is my first time posting on stackexchange. Constructive critisism and feedback are more than welcome. All regions in my custom theme are placed inside the body tag ...
0
votes
1answer
69 views

Twig: Generate classname from variable in views template

In the twig template file of a view with grouped rows I would like to add the title of the group as a classname. But the rendered classname from title variable is just "_" on every group. This is the ...
0
votes
0answers
23 views

add custom class for each field of a form

I am trying to create a custom class for the fields based on the title display dropdown for each field, and I have it most of the way working. I was wondering if anyone might have any ideas on this. ...
0
votes
1answer
64 views

Drupal 8: Node “options” does not exist for Node “Drupal\Core\Template\TwigNodeTrans” error after update

after updating Drupal 8 from 8.6.14 to 8.6.15 (twig v1.40.1) I suddenly get this kind of fatal errors: Uncaught PHP Exception Twig\Error\SyntaxError: "An exception has been thrown during the ...
0
votes
0answers
130 views

Twig and CSS for custom Block not working

I'm working on a custom module that has a block. This block has a form in configuration where user input the relative data, so far it works its saving the data and it display it but without a template ...
0
votes
0answers
35 views

Get the list of child pages for a book given the book node id

In a theme preprocess hook, I have the node id for a book. How do I get the list of child pages for the book? I checked the Book module API but see didn't a way to do it.
0
votes
1answer
25 views

<h1>Classification: {{ content.field_classification.value }}</h1> not displaying

Hoping someone can assist me please. I am trying to display the value of a custom field in a bootstrap sub theme I have created my node--testtype.html.twig template and that seems to work. I'm ...
2
votes
2answers
29 views

Does $element['#title'] need to be escaped with check_plain()?

I see (with grep) that the value of $element['#title'] in a render element is sometimes sanitized with check_plain(), and sometimes printed unfiltered. Which one is correct? Is the value considered ...
0
votes
1answer
34 views

Output data of different content types in same page

I have two content types : Content type 1 named book with two fields author and language Content type 2 named movie with two fields date and resolution In my-theme/templates/page.html.twig I want to ...
0
votes
0answers
11 views

How do I change the width of a mega slider?

I am using Drupal 7.x. I am using the popular theme is porto. https://i.stack.imgur.com/Kmhok.png Porto comes with a Mega Slider component. And that is what I am using here. I am using the Mega ...
0
votes
1answer
44 views

Print image URL with image style

I would like to print an image URL with an image-style. This doesn't work, since I don't have a ".value"-value for the image: How to find image style URL from within twig template? Is there anything ...
0
votes
0answers
32 views

How to include book traversal links on a custom twig template page

I use the Book module to create books with chapters. When I use the default twig template node.html.twig to display a book chapter, a section titled "Book traversal links" is included, with links to ...