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
79
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 ...
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.
50
votes
7answers
58k 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 ...
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 ...
42
votes
15answers
69k 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
43k 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?
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 error. ...
30
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
6answers
48k 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 ...
27
votes
4answers
23k views

How can I insert search box in page.tpl?

How can I insert search box(search block) in my theme programmatically?
26
votes
5answers
22k 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. ...
26
votes
3answers
55k 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'...
26
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()?
25
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 ...
25
votes
1answer
13k 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
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' ==$...
25
votes
4answers
30k 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
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
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?
23
votes
5answers
27k 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) {{ ...
23
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 $...
22
votes
5answers
39k 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?
22
votes
3answers
46k 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 ...
22
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?
22
votes
5answers
37k 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
36k 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
31k 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
4answers
18k 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 ...
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
22k 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 ...
19
votes
9answers
44k 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-...
19
votes
4answers
42k 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
3answers
13k 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 ...
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
743 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
5answers
13k views

Add JavaScript files to the administrative pages

How do I add JavaScript/CSS files in every administration pages, using a module?
17
votes
5answers
22k 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: ...
17
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 ...
17
votes
4answers
15k views

Best practice for third-party PHP class-based library

I am currently working on a module that requires a third-party PHP library, which is essentially a single PHP class. Normally, I would place it in an includes/ subdirectory and add files[] = ...
17
votes
1answer
24k views

How do I override the default page.tpl.php?

I have one page in my D7 website with significant deviation from the rest of my pages. In this page I will only display a limited number of regions and in a different layout. What is the best way to ...
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
27k 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 ...
16
votes
7answers
12k views

theming checkout pages in Drupal commerce

how do I theme the cart and checkout pages in Drupal commerce? I have set content, account, billing, and payment parts. Is there any --.tpl.php file to create?
16
votes
3answers
21k 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
3answers
14k views

Given a File ID (fid) how can I get the HTML that represents that fid?

I'm looking to do something like this $fid = 15; $file = (array)file_load($fid); $content = drupal_render($file); echo $content; file_load() drupal_render() And specifically this fid is from the ...
16
votes
4answers
11k views

How do I get $view->the actual row number?

How do I get the actual rows number in views-view-field--title.tpl.php in Drupal7 and views3? I know how to get the total by $view = views_get_current_view(); $view->total_rows; But how do I get ...
15
votes
4answers
19k 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....
15
votes
5answers
47k 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('')? ...