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
26
votes
4answers
32k 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
19k 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
16k 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('')? ...
14
votes
6answers
28k views

Rendering an image field in page.html.twig with a custom image style

I'm trying to set up a slideshow that's unique to each page. The code for this needs to be in page.html.twig. I've got the slideshow mostly working, but I can only call the full image URL, not a ...
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
13k 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'] = ...
2
votes
3answers
2k 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 ...
22
votes
5answers
38k 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
2answers
4k 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, ...
9
votes
2answers
16k 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: ...
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 ...
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 ...
2
votes
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
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' %} ...
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(&$...
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
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 ...
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, ...
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 ...
0
votes
1answer
433 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 ...
7
votes
3answers
16k 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?
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
25k 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. ...
16
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 ...
17
votes
2answers
25k 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
15k 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
21k 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 ...
12
votes
3answers
24k views

Pass Variable to Custom Block template file

I want to create my custom block with custom content in Drupal 8,in start I create Block with just simple text on it, and work correctly, my Problem is how can I pass my custom variable to it? I saw ...
7
votes
1answer
12k 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 ...
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

How do I theme checkout pages?

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?
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
28k 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 ?
8
votes
1answer
6k views

Restrict content to a user role in a template file

I want to restrict a single node to anonymous users in Drupal 8. I don't want to use any module for it as its useless for single restriction as per me. I know that I can do it with something like ...
7
votes
2answers
6k views

How do I theme a taxonomy term page?

I am working on Drupal 8, trying to get a page template for each vocabulary. I have tried using hook_theme_suggestions_HOOK_alter() to achieve this, but I was not able to do it. I tried using Devel ...
4
votes
2answers
7k views

How to create a custom Twig Template for Menu Block

I'm using a menu block to output a section of my main menu into a region so I can have a "In This Section" type of sub menu on every page. Unfortunately, I can't find a way to pinpoint in menu.html....
7
votes
6answers
4k views

How can I get numbered classes on rows?

I worked briefly with Drupal 7 and I thought it was possible there but in Drupal 8 is it possible to have a view output an increasing numbered CSS classes for Views rows? This is what I want. <...

1
2
3 4 5
20