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
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 $...
20
votes
6answers
35k 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: ...
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 ...
12
votes
7answers
17k views

image_style_url doesn't create images [closed]

I am using image_style_url to get a thumbnail of a picture I added through the administrator interface. // $foo->field_picture['und'][0]['uri'] has value public://foo.jpg image_style_url('foo-...
11
votes
5answers
18k views

hook_preprocess_page(): how to tell a views page?

Im writing a custom module that need to insert some javascript and css files only in a Views page. Im using hook_preprocess_page, but I can not tell if the current page is from a view: function ...
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", ...
10
votes
4answers
14k views

How to find image style URL from within twig template?

I'm implementing a node template that uses an image twice; once in a 'normal' way (i.e. using the image style defined in the field's display configuration for that view mode), and the other is as a ...
18
votes
5answers
50k 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('')? ...
10
votes
7answers
20k views

How to hide page title based on node type using template_preprocess_page()

I am trying to hide the title of the current page (as printed by page.tpl.php) if the current page is 1) a node in full display (as opposed to teaser mode), AND 2) the node type is either concert or ...
6
votes
3answers
11k views

How do you print View fields on Twig?

I have a view and added the title as a field. For example: How do I print the title? In Drupal 7 it was as simple as views-view-fields--[viewname].tpl.php <?php print $fields["title"]-&...
5
votes
2answers
7k views

Theme Drupal Form API checkboxes as a grid

I have a custom form that displays a form element of about 2 dozen checkboxes. I would like to output them 3 per row, in a table if possible. How can I go about doing that? $form['preference'] = ...
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="...
14
votes
1answer
4k views

Can I use the Twig template engine?

I do a lot of Django development and I like their templating language. Twig, the new templating engine in Drupal 8, looks very much like it. How can I use Twig in Drupal 7 or even Drupal 6?
8
votes
2answers
13k views

Dynamically adding a CSS class to a view row with template.php

I've actually reached the bottom of Google trying to figure out how to add a css class to each row of a view. The trick is that I need the class for each row to be dynamically determined based on ...
7
votes
1answer
3k views

How can I override or disable a parent theme's CSS file?

I am trying to override the menu.css file in the default Classy theme through my library file. I have read through the documentation, but anything I tried doesn't work. What would be the correct ...
20
votes
4answers
19k 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: ...
10
votes
7answers
13k views

Display comma-separated list of taxonomy terms?

Drupal 7. In my node.tpl.php, I want to print out a list of taxonomy terms (the taxonomy is called "channels."). If I use: <?php print render($content['field_channel']); ?> It works, ...
8
votes
3answers
3k views

Issue a html.tpl.php override from a module?

Is there a way to override the output of a page from a contributed module and issue your own html.tpl.php, effectively taking control of the output from the theme? I want to do this in effort to ...
6
votes
2answers
13k views

How to add CSS and JS files on node pages from theme's template.php

I am trying to add JavaScript and CSS files to one node type page from my template.php file but it is not working. Here is my template.php code: <?php // $Id: template.php,v 1.13 2010/12/14 01:...
8
votes
2answers
14k views

How to customize the user login form?

I'm trying to customize user login form in /user/login page and I want to use a hook_form_alter function to add some awesome style and placeholder to each of user login form fields and remove or hide: ...
7
votes
4answers
4k views

Sending a value to JavaScript

I have set theme handler for a form in Drupal and this handler has a template file. What is the easiest way to send a value from PHP to JavaScript in that include file?
4
votes
2answers
3k views

How can I dynamically add URL or taxonomy to body class

Am creating my own theme and have successfully added the URL into the node class in node.html.twig with {% set classes = [ 'url' ~ url|clean_class, ] %} but I need to be able to style each page ...
4
votes
1answer
4k views

How do you override page.tpl.php in Omega 4?

I am using the Omega 4 base theme, and am trying to override page.tpl.php. This file is in the base theme in sites/all/themes/omega/templates/system. When I copy it into my theme, edit it, clear ...
3
votes
9answers
11k views

Render form in template

I have made the following .tpl.php template: <?php print drupal_render($element["term"]); ?> <?php print drupal_render($element["search"]);?> <?php print drupal_render($element["...
1
vote
1answer
2k views

Drupal 8 create a template override for a view block within a custom module

The Question: In Drupal 8: How do I add a template override for a view block and have that twig file reside in a custom module - not my theme? Further Information: I have already created a custom ...
8
votes
1answer
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(&$...
8
votes
3answers
8k views

How to test for a boolean field in a twig template?

field_boolean is a boolean field. {% if content.field_boolean == true %} or {% if content.field_boolean == 1 %} or {% if content.field_boolean == 'true' %} or {% if content.field_boolean == '1' %} ...
7
votes
3answers
21k views

How do I define a template file for a specific node ID?

I'm trying to define a custom template file for a specific node, using the node ID. I read a lot of topics saying to create a node--X.tpl.php file in the templates folder. That's what I did; ...
4
votes
1answer
3k views

Is it possible to define hook functions in template.php instead of the module?

Theme functions are defined in the template.php but is it possible to define hook functions in there? for example There is a content type called phone-book, its add content form ID is phone-book-node, ...
4
votes
6answers
7k views

How to hide default “N/A” option for checkboxes?

I have a "gender" (checkbox) option that I want to show on the user profile page (but not on the registration page). The options are "Male" (default) and "Female". Since I don't make the field ...
1
vote
1answer
1k views

Optionally add image/icon after node title based on boolean content type field?

Using Drupal 7.10 with a Zen sub-theme. I have a custom content type, say Product. The products have titles such as "Wrench", "Hammer", "TV". I want to designate certain products as being a ...
1
vote
1answer
278 views

hook_theme_suggestions_page() provide default template file inside module folder

I am using hook_theme_suggestions_HOOK() to implement a custom template file in my drupal 8 website like below. /** * Implements hook_theme_suggestions_HOOK(). */ function ...
0
votes
1answer
427 views

do not optimize/remove html

I would like to have a page with some html content in it that CK Editor does not seem to support, in particular: I want to have a little <form tag with a couple of <input fields. I can enter it ...
4
votes
1answer
6k views

How renderable array for an image with style should look like?

I have a custom module that outputs some images. Now, I would like to render them properly. Currently, I use theme() function, kinda similarly to the way shown here1 and here1: echo theme('...
2
votes
2answers
2k views

how to add javascript with #attached and hook_page_alter

I tried to add js to pages by means of #attached, as it seems to be the recommended way. From what I understand, this involves altering a render array. hook_page_alter seems to me like good candidate. ...
2
votes
1answer
3k views

Filename for the front page template file

How do I create a theme for the front page only? I only want to change what is in the content area but leave the rest of the stuff the same from page.tpl.php.
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. ...
15
votes
5answers
20k views

How do I disable Twig and block cache for a specific module?

I'm working on a module in Drupal 8 which retrieves time sensitive data from an external REST api. The data is processed and forwarded to a Block. The final data is sent to a Twig template like so: .....
15
votes
1answer
5k views

How to make a theme hook suggestion for blocks according to region?

Since Drupal 8 it is not possible with template naming conventions to load a specific block template according to the region it is placed in ("Per-region block markup and per-region block templating ...
15
votes
2answers
22k 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 ...
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?
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 ...
7
votes
1answer
11k views

Get referenced node fields in twig

In Drupal 8, I have a content type, that has an "entity_reference" field and I wish to access the referenced node's fields in twig template. the kint() output for the field is: In this list I can't ...
8
votes
2answers
10k views

How to programmatically add links to the links variable

I am using Drupal 6 and would like to modify the $links variable to include other links programmatically. I have searched high and low on Google on how to do this to no avail. Does someone know how to ...
6
votes
4answers
20k views

Make views slideshow responsive - remove inline styles

How does one remove the inline hard coded styles of height and width from views slideshow? I'm trying to make views slideshow responsive. I'm trying to make my slideshow responsive (no i'm not ...
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 ...
15
votes
7answers
13k 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?
2
votes
3answers
1k views

Updated >= Drupal 8.0.5+: Rendering forms/entities programmatically on theming level

There are several attempts and questions already asked about near to that topic in combination with the new Drupal core (8), but non of them came down to the bottom of the basic question. And non of ...
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 ...
12
votes
5answers
27k views

Custom template for 404 error pages

A quick noob question here! How to set a theme to use a custom template for 404 error pages instead of using page.tpl ?

1
2
3 4 5
20