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
5
votes
3answers
2k views

Template suggestions based on path alias

I'm trying to work out how I can add my own template suggestions based on the set URL alias. I've found lots of information out there regarding Drupal 7, but very little for 8. I know I can use ...
4
votes
1answer
870 views

Theming Drupal fatal error messages

Whenever Drupal encounters an unrecoverable error, it displays an error message. Is there a way I can provide a template for this page?
4
votes
2answers
6k views

How to nest elements in a render array

So, I'm trying to generate some markup using render arrays. I need to create some nested divs. I thought that I could do this by nesting the arrays, as such: function make_array() { $items = ...
3
votes
1answer
2k views

How to override form element templates from custom module

I have a custom field with some radio inputs and the following (widget-)output right now: <!-- BEGIN OUTPUT from 'core/themes/stable/templates/form/form-element.html.twig' --> <div> <...
3
votes
1answer
5k views

Getting a custom block image field URL in the block Twig template

I have a custom block containing a text field and an image field. I would like to render the block so that the image's URL can be defined as a data attribute of the block's wrapper div so that it can ...
2
votes
3answers
4k views

In Views admin, is there a section to insert CSS to style the view? i.e. how to style view without editing theme code or other drupal PHP?

In the Views admin (i.e. admin/structure/views ), is there a section in the settings to insert CSS to style the view? i.e. how do I style a view without editing theme code or other drupal PHP? I am ...
2
votes
1answer
442 views

How do I theme the core modal with twig?

Drupal 8 comes with built in modals. This works: <a href="/node/11" class="use-ajax" data-dialog-type ="modal">modal</a> How can I style that modal using twig, to add new classes to the ...
2
votes
2answers
4k views

How to add custom css file to subtheme of omega kickstart theme?

I have created a subtheme of "omega kickstart theme" and I want to add some custom css files to it. I searched and got some solution(which didn't worked for me), the solution is as follows: create ...
2
votes
1answer
6k views

Calling a field in views-view-fields--view-name.tpl.php -— Error

I am trying to call a field by using the line of code: <?php print $field->handler->view->field['title_1']; ?> But i keep getting this error: I used devel dpm() to look for what was ...
2
votes
2answers
4k views

Adding more variables to menu for use in menu.html.twig

I'm attempting to give menus more variables to work with besides the default menu_name,items, and attributes. This is because making a variable in the preprocess menu hook does not allow it to be ...
2
votes
1answer
714 views

Conditional statement doesn't work in node.html.twig

I want to use {% if %} in a node.html.twig, but it doesn't work. I am using this code. {% if content.field_number == 0 %} zero {% else %} one {% endif %} It always print one. The following ...
2
votes
1answer
2k views

How a module can override theme suggestion?

Basically it was How to tell Drupal to look for templates in module directory? but I'll reword it, as I don't want to define a new theme (reason was already given). What I want to do: in my module I ...
2
votes
1answer
1k views

Render node author profile image in node template

I am working on customization Node template file in Drupal 8, I added another field to user in admin/config/people/accounts/fields ( my field is field_bio). Now I want to render author image( with ...
1
vote
3answers
9k views

How to print taxonomy terms field in node templates?

How can I display node taxonomy terms field in node templates of Drupal 8? We do this in Drupal 7 by add this code to node.tpl.php file: print render($content['field_tags']); I tried adding the ...
1
vote
3answers
6k views

Print author details for a node

How do I print the author details for a node? In particular, I am interested to the following values. Author picture Name Description In Drupal 7, I would use this code. <?php print $author_data[...
1
vote
2answers
4k views

How can I access raw field values in a view template?

I am writing a template for a views field in Drupal 8. How can I access the raw values of a multi-value field in views? I tried this but it doesn't work. {% for i in 0.. row.field_color['#items']|...
1
vote
1answer
3k views

How to add query parameters in twig using path()?

I am following the code snippet provided here {# Link to frontpage view. #} <a href="{{ path('view.frontpage.page_1') }}">{{ 'View all content'|t }}</a> {# Link to user entity/profile ...
0
votes
1answer
1k views

getting around recursion when dumping a node?

I'm working on a template and I'm using kpr() from devel to look at the values defined in $variables. One of them is the node in question, and what gets displayed is a big infinity sign indicating ...
8
votes
5answers
12k views

Theming the user registration form

I want to theme the user registration form in Drupal 7 by adding new markup, etc. I cannot seem to figure out how to do it. I've followed a few tutorials which suggested that you could simply invoke ...
7
votes
3answers
4k views

how to avoid fieldset in drupal date field

I have a date field in registration form, I am using template for that. When I using its outputs the html with fieldset. How can I remove that I wanna style likebleow fields. Please see the image ...
7
votes
2answers
9k views

Installing Bootstrap theme using Composer

I am new to using Composer. How can I install a theme, say https://www.drupal.org/project/bootstrap using composer I've tried: composer require drupal/bootstrap But didn't work. I also tried: ...
7
votes
2answers
8k views

How do I override a default view template from another module?

Drupal provides hook_theme(). But is there a hook_theme_alter()? I'm looking for something like hook_menu_link_alter(), which overrides hook menu entries, but for the theme. I want to modify a view ...
6
votes
2answers
8k views

Override module's template in theme

Suppose i have this hook_theme() in my module, choosing a template inside the module: /** * Implements hook_theme(). */ function module_theme($existing, $type, $theme, $path) { return ...
5
votes
2answers
8k views

Assign specific template to specific pages

H i I am quite new in Drupal and have been trying to figure out a way to assign a specific template file to some specific pages following the taxonomy like page--user--edit.tpl.php works but I don't ...
5
votes
2answers
14k views

How do I use a preprocess function for a node template?

I'm trying to preprocess my variable array in drupal 8, But it's not working well.I'm checked with the Bartik theme also, But getting the same error here. When I'm trying to print the variable array ...
5
votes
3answers
3k views

Using a different administration theme according to the role

Is there a way to use different administration themes according to the roles assigned to users? I have two roles (admin, editor), and I want that, when creating content, users with the admin role use ...
5
votes
1answer
16k views

Right way to start with a Bootstrap subtheme?

I create my first Bootstrap subtheme (version 7.x-3.0) and I have 3 questions: 1) Theres is the file css/style.css which has more than 6400 lines, is this normal. I expected to it to be an empty page ...
4
votes
2answers
3k views

drupal_get_messages always blank

the drupal_get_messages() function is returning nothing when run from page--front.tpl in my custom theme. Do I have to add something to page.tpl.php to build this? I have a print_r set up and it's ...
3
votes
3answers
2k views

Can an embedded video be made responsive?

I currently use the Video filter module to embed Youtube videos in my posts, but on mobile devices the videos are not responsive. They still maintain their width no matter how narrow the screen is. I ...
3
votes
2answers
382 views

Creating a responsive menu system for a site with a lot of content [closed]

I am currently creating a website which has a lot of content - text. For this I need a serious menu structure with 5-10 menu items per menu and at least 15 menu-blocks per main menu item. Further it ...
3
votes
1answer
5k views

Add CSS class to fields

I have the following snippet. function <themename>_preprocess_node(&$vars) { if ($vars['teaser'] && !$vars['is_front']) { $vars['theme_hook_suggestions'][] = 'node__teaser'; ...
3
votes
1answer
799 views

Where and why are style tags removed in the render process?

I have a block (in Drupal 8) that renders a field of a node. This is my build function: public function build() { $node = $this->getNode(); $build = array(); $markup = array(); $...
3
votes
1answer
1k views

Omega override simple-layout.tpl.php for content types

I have copied the simple-layout files and customized, the custom layout is simply mats2015.simple-layout (mats2015.simple-layout.tpl.php). I need to override this file for a specific content type (...
3
votes
1answer
3k views

Twig/Drupal caching and dynamic variables

I have a template with a list of recent articles and an article itself. I want to check in the list of recent articles if the article currently viewed is there and if yes add a class to the div. This ...
2
votes
2answers
2k views

How to add attributes to menu and menu items on the block level in THEME_preprocess_block()?

With THEME_menu_tree() we can change the markup of the <ul> element and with THEME_menu_link() we can add css classes to the items of it easely. But what if we have an IF IS IN THIS BLOCK ...
2
votes
2answers
849 views

Show field twice in node page

I created a custom bundle (content type) and I've created fields One of those field is a file type field, is a video file, stored in the private storage. I installed the videojs module to allow to ...
2
votes
1answer
126 views

Remove the cache for a particular Twig file

I'm showing the name of the currently logged-in user in header, using \Drupal::currentUser()->getUsername(), but it's showing an already cached page. I know I can disable the cache for a ...
2
votes
1answer
3k views

Trying to remove options form an exposed filter

In drupal 7, I'm trying to remove an exposed taxonomy filter. This taxonomy filter has a depth of 2. I'm only trying to expose the parent item. As a quick fix I'm trying (poorly) to remove them with ...
2
votes
2answers
438 views

Language name of translated node

For a teaser view mode I want to display the language of the content. I can get the langcode in twig with: {{ node.langcode.value }} But how can I display the language name? In the field display I ...
2
votes
1answer
3k views

How to render HTML into a variable programmatically

Let's assume you have a "product" node $node, and for some reason you want to render HTML from $node into a variable $html using a Twig template. I'm a bit desperate yet, what would you do? ...
2
votes
2answers
887 views

Drupal 7 website layout/styling breaks all a sudden (random), how to debug? there are no logs

One of my websites running Drupal 7 goes out of format, most often when user login. This is how it should be After running out of format this how it looks This may be a CSS issue, it may be a ...
1
vote
1answer
590 views

What are my options to visualise a views table with many fields grouped in columns?

I have a view with 30 fields. Displaying its results would look best using a table, but with fields grouped in columns. Default table in Views can't do this because there are to many fields. So ...
1
vote
1answer
949 views

Wrapping multiple cck fields into a single div tag for theming?

I have a content type that uses many cck fields, and I would like to theme the content type by grouping certain fields in "blocks" (not Drupal blocks but div blocks), preferably div tags, so that the ...
1
vote
1answer
143 views

When should I add a new tpl.php file, and when should I implement a theme function?

Two part question, both highly related. Can all templates be implemented both as a function in template.php, and as a separate tpl.php file? In the cases where you can do both, are there advantages ...
1
vote
1answer
468 views

preprocess_node_webform is not working

I wanted the error messages from the webform to be customised. So I wrote following piece of code in template.php of my theme. function sandesh_preprocess_node_webform(&$vars, $hook) { if ($...
1
vote
2answers
370 views

Show create content menu item to ananymous users but call URL for login/register popup on click

I thought it would be simple to do, but after lots of searching I couldn't find exact solution for it. So the issue is, I have 2-3 main menu items which I have to show to anonymous users but have to ...
0
votes
2answers
408 views

How to apply suggested theme hook using hook_theme_suggestions_HOOK?

Following this answer, I'm trying to override core/themes/seven/templates/node-add-list.html.twig using hook_theme_suggestions_HOOK. So, I added the following function in modules/custom/...
0
votes
1answer
331 views

Add inline style to render array attributes, without XSS filtering

I wish to use an inline style to add a dynamically generated background image URL to a div, e.g. $build[0] = [ '#type' => 'container', '#attributes' => [ 'id' => '...
0
votes
3answers
2k views

How to switch logo and menu links based on subdomain?

my D7 site will be accessible from 4 different subdomains: - a.site.com - b.site.com - c.site.com - www.site.com (or just site.com) I already enabled a domain cookie for .site.com and the login works ...
-1
votes
1answer
121 views

Simplest way of creating a themed page from a module

Unifying the questions below, I want to check if the problem and solution is correct: Problem: I want to create a page with hook_menu from my custom module. This page will have a different template ...

1
3 4
5
6 7
20