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
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 ...
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.
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 ...
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
63k 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 "...
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?
33
votes
7answers
9k 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
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, ...
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
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 ...
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
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
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 ...
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 @...
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
5answers
38k 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
6answers
15k views

Correct way to change the active Drupal theme programmatically?

What is the correct way to change the active Drupal theme programmatically?
22
votes
3answers
43k 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
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
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
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"> ---...
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 $...
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'...
20
votes
4answers
16k 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
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 ...
20
votes
3answers
15k 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
17k 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
21k 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
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-...
19
votes
5answers
30k views

How to add additional display(view mode) for node?

I am creating a custom content type. By default, nodes support only two view modes (full and teaser): function mymodule_view($node, $view_mode) { if ($view_mode == 'full') { $node->...
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
742 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 ...
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
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
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
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
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
10k 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
8answers
24k 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 ...
15
votes
4answers
12k 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 ...
15
votes
3answers
19k 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 ...
15
votes
5answers
10k views

How To Show Node Comment Count in node.tpl?

I have had the bright idea of changing my user permissions so as guests cannot see the comments on a node. I have no problems with Views around my site, as they can clearly see there are comments on ...