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
80
votes
14answers
52k 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 ...
58
votes
6answers
86k 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.
50
votes
7answers
61k 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 ...
47
votes
3answers
29k 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 ...
46
votes
16answers
87k 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) ...
39
votes
9answers
68k 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 ...
39
votes
9answers
44k 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 "...
37
votes
4answers
21k 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?
35
votes
5answers
79k 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'...
33
votes
7answers
10k views

How do I prevent Drupal raising a segmentation fault when using a Node.js theming workflow?

Symptoms: Some drush commands fail; Some Drupal pages are blank. The failing drush commands report "Segmentation fault: 11" The Apache log (e.g. php-error.log in MAMP) also shows the same ...
31
votes
4answers
24k 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 ...
31
votes
2answers
33k 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, ...
29
votes
5answers
24k views

How do I add JavaScript specific for a view?

I have a view in my site that has a specific class name. I want to know, inside the template.php file of a theme, how I can know if a view with specific class name is available in the requested page. ...
27
votes
4answers
24k views

How can I insert search box in page.tpl?

How can I insert search box(search block) in my theme programmatically?
27
votes
1answer
12k views

what is the difference between render() and drupal_render()?

what is the difference between render() and drupal_render() anyway ? Is there a reason to use only drupal_render()?
26
votes
3answers
58k 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 ...
26
votes
4answers
31k 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 ...
25
votes
8answers
38k 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) {{ ...
25
votes
6answers
45k views

Adding form placeholders to text input fields

Is there a way to convert a regular form and add placeholders with a module, or should this be done with a form template or with jQuery?
25
votes
3answers
37k views

How do I get the node URL in a Twig template?

I am trying to get the node URL in a Twig template. {{ content.node_link }} returns the full link, but I only need the URL. How do I retrieve the node URL?
25
votes
1answer
14k views

Can regions be printed within a node template?

Can regions be printed within a node template, or are regions strictly confined to page templates?
25
votes
5answers
22k 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' ==$...
25
votes
1answer
6k views

Why does Drupal 7 prefer CSS @import rules to <link> tags?

"Don’t use @import," lots of guys say. There are lots of shortcomings of using @import. Using @import within a stylesheet adds one more roundtrip to the overall download time of the page. Using @...
24
votes
6answers
21k views

Using built in jQuery UI in my theme

Every page of my theme will need to use jquery UI. I know it's included with Drupal 7, but I can't really decipher Drupal's way-too-technical documentation. It looks like the only way to do it is ...
24
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 $...
23
votes
6answers
16k views

Correct way to change the active Drupal theme programmatically?

What is the correct way to change the active Drupal theme programmatically?
23
votes
1answer
2k views

Why does core use print rather than echo?

I've read somewhere, and I don't remember where, that echo is a more efficient way of outputting data then print. Why does Drupal core use print so much? Is there any special reason behind that?
22
votes
6answers
46k 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 ...
22
votes
5answers
37k views

Hide a field label

Is there a way to hide the field label when rendering a custom field in Drupal 7? In my node template I have: <?php print render($content['field_image']); ?> Which gives me: <div class="...
22
votes
4answers
32k views

How to add classes to BODY tag dynamically based on page path/depth?

How to add classes to the body tag dynamically such as this example below? -Home -Cities       --Melbourne       <body class="melbourne"> ---...
21
votes
8answers
39k views

How do I get the base path?

I want to use the base path in a Drupal 8 template file. I tried the following, but I don't get the correct result. {{ app.request.baseUrl }} {{base_path}} What I need is the absolute path to the ...
21
votes
6answers
25k views

Include a partial template

I'm trying to use Drupal 8, with a custom theme, due big structure differences for my requirements I have a page--front.twig.html and a page.twig.html, I would like to create template parts as used in ...
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!...
20
votes
4answers
18k views

How to override some admin theme CSS rules? [closed]

Is there a way to override just some CSS rules used by the admin theme, without touching the admin theme itself (via some theme functions or module hooks)? For example, I'd like to add a text-align: ...
19
votes
6answers
34k 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: ...
19
votes
4answers
44k views

How to edit <head> info

In Drupal 6 the entire page data was stored in page.tpl.php. Now, with Drupal 7, only the content that appears in between <body> and </body>. So how do you edit the HEAD info? Is it still ...
19
votes
4answers
3k views

Best practices for page layouts

I'm trying to figure out what the best practices are for page layouts in Drupal. Many pages have several different elements on them like main content, a header image, etc. I'm not looking at ...
19
votes
2answers
763 views

What is the benefits of Panels for a themer?

I've never thought much of Panels, as I have always been comfortable with writing my own themes. However, I have seen a lot of articles advocating the virtues of Panels (from Lullabot & Active ...
18
votes
9answers
45k 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-...
18
votes
5answers
49k views

render or print image in a drupal 7 node.tpl?

I am trying to theme a node with tpl and when i tried to print image , I cant find image path like in d6.. which function i have to call to properly output image .. I mean something like theme('')? ...
18
votes
3answers
14k views

Add classes to form select option item

How can I add classes to a form option tag without JS? At the moment in Form API I can pass a keyed array like this array( '0' => 'option 0', '1' => 'option 1', ) and I'll get html like ...
17
votes
4answers
26k views

Verify a field is not empty

What is the best method to check if a field is empty in a node template. In node--example.html.twig we can use "content" variable. I can't use check like checking a block {% if content....
17
votes
6answers
24k views

How to print custom date format in Twig?

How can I print a custom date format in Twig? First of all my I am trying to edit the field.html.twig of the field called field_publication_date, in that file I find this variable {{ item.content }} ...
17
votes
5answers
19k views

Check if the user is logged-in in a theme

In Drupal 7 we can simply check if the current user is logged-in in a theme by checking $GLOBAL['user']->uid or using user_is_logged_in(). How can I check if a user is logged-in in a page ...
17
votes
5answers
14k views

Add JavaScript files to the administrative pages

How do I add JavaScript/CSS files in every administration pages, using a module?
17
votes
3answers
3k views

How to handle / cleanup obsolete aggregated css / js?

I'm only using Drupal 7 built in CSS / JS aggregation, however the files folder where the css.gz and js.gz files live are filling up at a fairly rapid pace, and while I'm sure it'll be a while before ...
16
votes
8answers
11k views

How can I make kint() load faster when debugging twig templates?

I've seen quite a bit of discussion about how kint() from the Devel module is difficult to work with because it maxes out PHP memory limits and makes the browser drag. I've heard some thoughts on ...
16
votes
3answers
27k views

Render plain text as HTML in Drupal 8 twig

I've run into a wall trying to render a svg image markup code into html from a plain text field. I'm looking to render the svg code from a plain text field without overriding the plain text field ...
16
votes
2answers
12k views

Override html.tpl.php per node type

In my template.php file for my theme I have tried the following: function media_preprocess_page(&$vars, $hook) { if (isset($vars['node'])) { // If the node type is "blog" the template ...
16
votes
10answers
19k views

Add class to content field (link)

I want to add a class to the <a> tag of a field that consists of a link and text. (It's a field of type Link.) The name of the field is content.field_c_button_link. In the template file, I ...

1
2 3 4 5
208