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
45 votes
9 answers
154k views

How do I get the raw field value in a twig template?

myfield is a plain text field. {{ content.field_myfield }} renders the field with HTML markup and the field label. How do I render the raw value of the field? {{ content.field_myfield.value }} doesn'...
Pim's user avatar
  • 1,055
62 votes
14 answers
137k views

How to get the valid URL of a Link field from within a Twig template?

I have a Link field named field_my_link (machine name). Within a Twig template I can get the link's URL value with this: {{ node.field_my_link.uri }} If inside the Link's URL there is an external ...
Andrea's user avatar
  • 1,267
6 votes
2 answers
11k views

How to safely render node body on a custom variable?

I created a custom template for my programmatically created block. I defined a variable for the template called test so in my render array I have '#test' => $node->get('body')->value ...
No Sssweat's user avatar
  • 31.4k
51 votes
7 answers
64k views

How to a use a template file to theme a form?

While nodes, comments, blocks and many other things in Drupal are themed using theme template files (like node.tpl.php), forms are a different story. There are no theme template files for forms. How ...
Chaulky's user avatar
  • 6,453
9 votes
2 answers
9k views

Change a normal submit 'input' type to 'button' type with button tag

Is it possible in Drupal 8 to change a regular form submit button from Drupal into a button tag? This is the output I need to achieve: <button type="button" class="search-box__button"> <...
Kevin's user avatar
  • 27.9k
58 votes
6 answers
88k views

How do I create custom regions in a theme?

I want to add a new area which will be site wide. Describe the process of getting this new region into my theme, if possible generalize it for adding any new, custom region.
palbakulich's user avatar
  • 1,367
49 votes
3 answers
30k views

How to provide template for particular view mode?

I want to theme the search result view mode with a template. I had it in my head that naming a template file node--article--search-result.tpl.php would do the trick, but I'm obviously wrong about ...
artfulrobot's user avatar
  • 4,019
12 votes
5 answers
34k views

How to print paragraphs in twig template?

I have a content type, basic, where i have added a Paragraph field field_pr that has two fields: field_text, field_color. I have a twig template node--basic--full.html.twig where I want to print the ...
usernameabc's user avatar
  • 2,726
11 votes
5 answers
42k views

Get current language in template

In Drupal 7 the current language is a global variable we can access with global $language; $langcode = $language->language; I want to know how can we access the current language in a Twig file ...
Yuseferi's user avatar
  • 22.1k
4 votes
2 answers
4k views

How to render specific form elements from the *.theme file

I am using Drupal 8 and would like to customize how form elements are being displayed. Specifically, I don't like how uneditable, populated textfields are displayed as plain text. I would have it ...
user5013's user avatar
  • 1,497
18 votes
9 answers
47k views

Create template file for views block

There is a lot about theming custom blocks, but what about blocks created by views? My views block has id: block-views-posts-listing-block, I try many ways for naming template file, ex: block--block-...
Codium's user avatar
  • 4,955
12 votes
2 answers
26k views

How do I theme a webform? [closed]

I am in need to theme webform in D7. How can I do that ? In the search I've come to know that by using web-form-nid.tpl.php we are able to theme a drupal individual form. Could any one guide me in ...
Fero's user avatar
  • 1,547
9 votes
2 answers
10k views

Override theme template from module without implementing a theme

I have a project on D8 where I don't use any custom themes, I use default seven theme for everything because there is no need of any visual theming. So My question: Is it possible to override theme ...
otarza's user avatar
  • 954
3 votes
1 answer
4k views

Custom registration twig template

What would be the best way to make a custom registration twig template ? I have implemented the hook : function THEMENAME_theme_suggestions_form_alter(array &$suggestions, array $variables) { ...
Aporie's user avatar
  • 365
81 votes
12 answers
55k views

Any way to add CSS for a single page/node?

I'm cleaning up my big crazy style sheets (possibly pertinent to a future question) and I'm wondering the best way to add custom CSS to a specific node or page. In particular, my work site's home page ...
epersonae's user avatar
  • 1,290
43 votes
9 answers
47k views

How do I change a theme based on the URL?

I have a Drupal instance running on example.org. Which has a theme X installed and activated. Now for a limited period an event is supposed to be held on the site for which a special section has been "...
Samyak Bhuta's user avatar
9 votes
2 answers
21k views

How do I add JavaScript to a site?

How can I add JavaScript and CSS to my site?
kinkajou's user avatar
  • 223
8 votes
3 answers
493 views

Is there a more performant alternative than overriding template files?

I've got to get rid of a lot of unnecessary markup in a view. In general, I accomplish that by overriding the template files in my theme, but this time the view is really huge and performance is going ...
Madam Adam's user avatar
5 votes
1 answer
7k views

Extracting URI value from Image in Views - Getting Index Error

I am trying to create a custom slideshow using Views. Please not that I am not using the Views Slideshow Module What I need to accomplish is to wrap the the relative URL for the images within a ...
Allan's user avatar
  • 563
6 votes
2 answers
9k views

Change templates based on path alias

What is the easiest way to select a template based on path alias. For example, if I have the following URLs: http://www.example.com/mydirectory/page1 http://www.example.com/mydirectory/page2 http://...
Jane's user avatar
  • 1,805
2 votes
1 answer
601 views

How can I theme individual fields in a row?

I'm having trouble doing something that I think should be relatively simple Drupal 8 views. I have a content type called Countries. I would like to display the 3 latest country nodes on my homepage ...
Kaizen9001's user avatar
41 votes
4 answers
43k views

Pass raw html to #markup

I have some html content, it comes from a external library so i can not change it, it has many <span> and <div> tags with attributes like: <span style="color: #0000ff;">, but when i ...
Yukare's user avatar
  • 541
37 votes
5 answers
89k views

Get path to theme assets in Twig template

I have a question about getting a path to an image in a Twig template. The image is not assigned to a field or something. Just a static image which is stored in "MYTHEME/image/icon/my-icon.png". In ...
Yetispapa's user avatar
  • 697
36 votes
8 answers
67k views

Iterate through multiple value content field in Twig template

I need to take control over the rendering of a field_admin_tags field in a node.html.twig template. This WORKS: {{ content.field_admin_tags }} — Renders everything (label + all field values) {{ ...
AngularChef's user avatar
  • 1,005
13 votes
2 answers
6k views

Override field template with custom module

Instead of adding tpl files (in this case, media-youtube-video.tpl.php) to the theme. How can I override field templates from a custom module? Including when the field is used in a View.
Allan Thomas's user avatar
12 votes
2 answers
17k views

Where is links__system_main_menu defined?

I searched for links__system_main_menu, but just find usages of this theme. Where is it defined?
hpn's user avatar
  • 2,398
9 votes
1 answer
18k views

Send a form to twig template

How I can pass a form to twig template in Drupal 8? For example, I get this: a form: mymodule/src/Form/MyForm.php Then on my Controller: public function myController() { ?????? return [ ...
rpayanm's user avatar
  • 3,611
9 votes
1 answer
18k views

How can you render fields from an entity reference in node templates? [Drupal 8]

For context, I'm dealing with two content types: article and team_profile. In article nodes, we have an entity reference field pulling a team_profile node in to serve as the author information. I ...
alexbea's user avatar
  • 203
9 votes
1 answer
4k views

Working with template suggestions on Drupal 8

I need Drupal to use a custom page template if the URL contains a particular _GET parameter. In D7 I would do something like this in the theme's template.php: function mytheme_preprocess_page(&$...
Sifro's user avatar
  • 440
7 votes
3 answers
21k views

How do you theme a content type's create/edit form?

Like it says -- I've got a D7 content type whose editing form needs to be themed. I did this all the time in D6 by registering theme functions in template.php and writing the associated theming ...
Jim Miller's user avatar
  • 1,948
39 votes
4 answers
22k views

What is the template suggestion for node 'teaser' view mode?

node--[type|nodeid].tpl.php targets to node's default view mode. However I want to override the template for teaser view mode. What is the template suggestion (.tpl.php file) for 'teaser' view mode?
gilzero's user avatar
  • 6,037
31 votes
2 answers
36k views

Eliminate render-blocking JavaScript and CSS in above-the-fold content

I am building a Drupal 7 site. These are some of the modules I use: Adaptivetheme (theme), Views and Content Panes, Panels, Mini panels, Panels everywhere, Page manager, Superfish for menus, Addthis, ...
EB84's user avatar
  • 1,417
25 votes
5 answers
26k views

Preprocess function per content type

I have a couple of content types which I need to preprocess in different ways. So template.php in my theme foo currently looks like: function foo_preprocess_node(&$variables) { if ('news' ==$...
cherouvim's user avatar
  • 1,937
20 votes
3 answers
17k views

specify $form elements to be excluded from display?

I want to hide certain elements in form using form_alter or a template file. I have read somewhere that in Drupal 7 , we can specify $form elements so it will not display in form, but I can't remember!...
Serjas's user avatar
  • 1,357
18 votes
3 answers
34k views

How do I show the current node title in page.html.twig OR in node.html.twig?

If I want to show the current node title in page.html.twig (by default it seems to only be available in node.html.twig) I have to create a preprocess function like so: function theme_preprocess_page(&...
Greg's user avatar
  • 852
16 votes
7 answers
45k views

Rendering an image field in page.html.twig with a custom image style

I'm trying to set up a slideshow that's unique to each page. The code for this needs to be in page.html.twig. I've got the slideshow mostly working, but I can only call the full image URL, not a ...
JacobTheDev's user avatar
14 votes
5 answers
25k views

How can I add a CSS class to the body tag?

I'm trying to add a custom CSS class to the <body> tag, How can I modify or pre-process the <body> tag to add the class body, Is it right to style the <body> tag with css file?
Mojtaba Reyhani's user avatar
13 votes
5 answers
21k views

How to override page title by content type

I'm using the pagetitle core module to render a page title. However, for certain content types I want the page main title to be the content type label (e.g. "News") and not the node label (e.g. "...
Filipe Miguel Fonseca's user avatar
12 votes
3 answers
17k views

Page template suggestions are not working

I've created a theme and have my template files in this structure /templates/page/page.tpl.php /templates/page/page--node-type.tpl.php I've created a custom page template but for some reason it's ...
Paul Sheldrake's user avatar
12 votes
1 answer
15k views

How to set Media Styles in Media 7.1.2 / Media 7.2.X?

Where is the latest form of the component in the Media project family that allows styles to be defined for Media files? I see a lot of references to the idea that the Media module contains, once ...
user56reinstatemonica8's user avatar
11 votes
3 answers
32k views

How to get an image URL from a field in a twig template

I have a node that contains various fields. I am able to get the values of text fields but not an image field. Below is the relevant output of the node variable being dumped in the twig template: '...
Adeleke Akinade's user avatar
9 votes
7 answers
20k views

Adding Theme Suggestions Programmatically For Views (Rows & Fields)

For a site I'm currently building I've got a variety of views, all with multiple display modes for different pages. For example, I have a venues view, one block is named listing which lists all of my ...
Daniel Dewhurst's user avatar
8 votes
2 answers
12k views

How do I alter a language item link?

I am looking to modify the default output of Drupal 8 of links in a certain situation, the language switcher. Ideally I want to be able to do that in a twig template and not have to produce a massive ...
Guillaume Bois's user avatar
7 votes
3 answers
6k views

How to customize the default search block form template?

How can I customize the default search block form template, I now use below template to display a search form block, but this code doesn't allow me to edit and customize each part of this form ...
Mojtaba Reyhani's user avatar
7 votes
5 answers
29k views

Customizing menu link output

In Drupal 7, how I can intercept menu rendering in template.php and add pipes after menu links? I tried using template_preprocess_menu_tree but I don't think that is what I am looking for. I want to ...
Kevin's user avatar
  • 27.9k
5 votes
5 answers
16k views

Custom page template for content pages

Is there any way to make a custom page.html.twig template in Drupal 8? By default, Drupal generates some suggestions, but I'm looking for something like page--node--content-type.html.twig.
Eduard Pochtar's user avatar
4 votes
6 answers
14k views

How do I insert a <span> </span> tag inside the <a> </a> tag on my main menu

I have asked exactly this question on Stack Overflow, but it makes more sense to ask it here. I'm trying to make the text between my tag not display by wrapping it in a and then styling that. I've ...
Martin Duys's user avatar
3 votes
2 answers
6k views

Accessing node value in paragraph twig template

I'm writing a twig template for a paragraph. I'd like to access a text field value from the page/node where this type of paragraph will be added. Specifically, I'd like to access the value of a text ...
scaffolding's user avatar
3 votes
1 answer
13k views

How to theme webform elements (radio buttons etc.)?

I would like to know how to theme Drupal 7 Webform elements? I want to change the HTML structure of every element, not just wrap form with div or something like that. And I want to leave theme's ...
gregab's user avatar
  • 507
2 votes
1 answer
8k views

How to correctly use cookies? (Twig and cache context)

In my current project I need to alter node templates depending on previously visited landing page. My idea is that, when a visitor visits one of these landing pages, a cookie will be set, and ...
Hudri's user avatar
  • 5,539

1
2 3 4 5
21