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
21
votes
3answers
48k 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'...
49
votes
7answers
57k 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 ...
27
votes
5answers
43k 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 ...
58
votes
6answers
85k 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.
46
votes
3answers
28k 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 ...
78
votes
14answers
50k 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 ...
21
votes
5answers
34k views

Get Image URL in Twig

I want to render an image as a background image via an inline style in twig. I created a field called bg_image and attached it to the standard plain page. After fiddling around for hours I was able ...
19
votes
9answers
43k 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-...
10
votes
2answers
23k 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 ...
9
votes
2answers
18k views

How do I add JavaScript to a site?

How can I add JavaScript and CSS to my site?
4
votes
6answers
8k 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 ...
2
votes
1answer
4k 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 ...
42
votes
15answers
64k views

Getting the image URL from a field_image on a node

So I have this Node: object(Drupal\node\Entity\Node)[1862] protected 'values' => array (size=17) 'vid' => array (size=1) 'x-default' => string '7' (length=1) ...
38
votes
9answers
42k 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 "...
14
votes
2answers
16k 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?
7
votes
2answers
8k 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://...
5
votes
2answers
4k 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"> <...
4
votes
3answers
15k 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 ...
8
votes
3answers
336 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 ...
11
votes
5answers
13k 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. "...
30
votes
2answers
32k 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, ...
7
votes
3answers
19k views

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

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 ...
9
votes
1answer
12k 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 [ ...
8
votes
1answer
14k 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 ...
13
votes
2answers
5k 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.
4
votes
6answers
11k 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 ...
2
votes
2answers
4k 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 ...
1
vote
2answers
1k 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 ...
5
votes
2answers
7k views

Adding a class to “body”

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?
36
votes
4answers
20k 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?
12
votes
1answer
14k 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 ...
25
votes
5answers
21k 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' ==$...
20
votes
3answers
16k 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!...
12
votes
3answers
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 ...
3
votes
1answer
12k 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 ...
6
votes
2answers
2k 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 ...
6
votes
5answers
11k 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.
12
votes
3answers
14k 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(&...
7
votes
2answers
6k 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 ...
7
votes
5answers
26k 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 ...
3
votes
5answers
7k 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 ...
1
vote
1answer
180 views

How to set the values of some fields depending on the value of a list box?

Remember the create password page of Drupal! while you are entering characters it tells you how string is your password! now I want to have something like this in a list box but a bit different. I ...
2
votes
1answer
1k 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) { ...
22
votes
5answers
24k 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) {{ ...
22
votes
3answers
44k views

get path to image (src) from twig template

i have a question about getting a path to an image in a twig template. The image is not assigned to an field or something. Just an static image which is stored in "template/image/icon/my-icon.png". ...
22
votes
2answers
14k views

Print $Messages in node.tpl.php file

In Drupal 7, by default the $messages variable is printed in page.tpl.php. Is there a way to print $messages in a node.tpl.php file (e.g. $node-mycontenttype.tpl.php). Just putting <?php print $...
14
votes
5answers
20k views

How to get each field value in views-views-unformatted--view-machine-name.html.twig?

I have an twig file: views-view-unformatted--view-machine-name.html.twig {# /** * @file * Default theme implementation to display a view of unformatted rows. * * Available variables: * - title: ...
11
votes
2answers
15k views

Render a node field inside page.html.twig

I have an image field on my content type (field_hero_image). I don't want it to render in the node.html.twig file. However, I DO want to render it in the page.html.twig file. Specifically, I want to ...
5
votes
1answer
7k views

Correct way to render a modules output through a template?

I usually do exclusively functionality on a site, and as such I'm familiar with php and Drupals APIs, but I'm mostly lost in the theming layers. I find myself with these pieces of code, that "work", ...
25
votes
4answers
29k views

How to theme a custom block

I've created a block using hook_block_info and hook_block_theme and the like. But how can I theme it? I have it working to return an array with the keys 'subject' and 'content'. But I created the ...