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
7
votes
1answer
13k views

How to get Media entity image (Entity Reference Field) URL in TWIG theme

Apologies if this question has already been asked. However, in my research I found the answers have been for simple image fields which are in default install of Drupal 8. However, in order to have ...
12
votes
5answers
6k views

Export/Deploy Drupal site/page to static? (no cache)

I wonder if there is an existing module that can help in the subject. I am not looking for a caching module (like Boost or Varnish), but a way to export my whole site (or only certain pages) into ...
12
votes
4answers
6k views

Right way to add JS and CSS to node/edit and other forms

I am making a site with a lots of JS, and I am wondering where I should put the JS code. Optimally I would like to keep the JS with each module and not the theme layer. Some content could be exposed ...
8
votes
1answer
4k views

Field template for display mode

I have a template for my field: field--field-category.html.twig. Is there a way to override this for a specific Display Mode? A have a mode called teaser block. I tried field--teaser-block--field-...
8
votes
1answer
4k views

how to install package via composer?

I would like to add library to my drupal 7 custom module. Library can be installed via composer, but i can't find a solution for install? How can i install this library? I have installed "composer ...
5
votes
1answer
7k views

Accessing a field collection

My content type uses a field collection (field_site_web) to allow users to enter multiple websites, consisting of a name (field_site_name) and an internet connection (field_link). I want to use a ...
5
votes
1answer
3k views

Drupal 8 - “Implement menu links as plugins”, trying to build a menu tree

In a previous Drupal 8 menu question here, we determined that menu tree building was now a service. In my D8 contrib theme, I was then able to render the main menu tree as: function ...
18
votes
3answers
28k views

How can I render plain text as HTML in a template?

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
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 ...
14
votes
5answers
29k views

Check if it's the front page in the template

Im trying to show content when I'm on the front page of my Drupal 8 test website, but the content shows on every page: {% if front_page %} <header role="banner"> {% if logo %} <a ...
13
votes
5answers
11k views

Force a page to be rendered in admin theme (overlay mode)

Is there a way to force a page to be rendered in admin theme, Like pages that their path begins with 'admin/'?
11
votes
4answers
15k views

Using Twig how can I get the summary of the body field to use in a template?

So I have a textarea with summary and I want to display the summary before the content. So if I just use {{ content.body }} the text is displayed without the summary. How can I get the summary ? {{ ...
11
votes
5answers
9k views

How to tell Drupal to look for templates in module directory?

I'd like to provide template implementation in my module and allow themes to override it. Basically, I add a suggestion by this simplified code: function attach_preprocess_node(&$vars) { $vars['...
10
votes
2answers
8k views

Printing regions in html.tpl.php

I need to output some regions in the html.tpl.php template since these don't change between page.tpl.php and page-front.tpl.php (just to name two). Basically I want to avoid code duplication. However ...
8
votes
5answers
10k views

Adding JS to a Drupal 8 theme (replacement for drupal_add_js)

In Drupal 7, I can use drupal_add_js within a theme's template.php file as a theme_preprocess_html(&$vars) function: drupal_add_js(drupal_get_path('theme', 'mytheme') . '/js/scripts.js', ...
7
votes
4answers
11k views

Theming user_profile_form (the user edit form)

I am looking for easy ways to theme the user profile form that will allow me to setup a two-column layout for the form and exclude certain elements. How can I achieve it?
5
votes
6answers
11k views

How to add the current title to the breadcrumb without preprocess function?

I'm trying to get the title into my breadcrumb path without using a preprocess function. Drupal 8 Add the current title to the breadcrumb shows how to do it with preprocess function which is not what ...
5
votes
1answer
12k views

How do I overwrite node title for specific content type?

I'm trying to add a chapter tag (§) in front of a title for content type 'ABC' in a Drupal 7 site. I tried the following: function mytheme_preprocess_node(&$variables) { if ($variables['...
5
votes
1answer
3k views

Remove specific stylesheets from a given page

Adding a stylesheet to specific pages is easy: implement hook_preprocess_page(), call drupal_add_css(...) and set $vars['styles'] = drupal_get_css(). But what is the proper way to remove a stylesheet ...
1
vote
2answers
3k views

How to show in different positions exposed filters in a View?

I would like to design my view in this way: EXPOSED FILTER1 EXPOSED FILTER2 MyView resulting output........... EXPOSED FILTER 3 .......................
0
votes
5answers
8k views

How can I display site logo, name and slogan?

how can i show site logo, name and slogan Separately in custom area in my site theme, I now use this code to display theme, buts this code don't allow me to edit each of them Separately. {{ page....
12
votes
2answers
14k views

Overriding views-view-fields.tpl.php

Is it possible to override views-view-fields.tpl.php file for a specific view? I've tried creating a views-view-fields--view-name.tpl.php file and have re-scanned template files and cleared the cache ...
11
votes
1answer
4k views

Add a class to a Drupal table cell containing ['data']

In Drupal 8, rendering Tables is still a lot like Drupal 7. You build out multi-dimensional arrays of rows and columns in PHP that Drupal transforms into a <tr> and <td>s respectively. ...
11
votes
6answers
8k views

Splitting up content fields into different regions

My situation is as follows: I have a content type Seminar, with fields A, B, and C. I have regions Header, Footer, Content, and Sidebar Left. There are some fields in Seminar I want displayed in the ...
10
votes
1answer
14k views

How to programmatically render a node's teaser using the theme layer?

How do I programmatically render a node's teaser using the theme layer?
8
votes
2answers
2k views

How to find elements in a render array

I just spent a lot of time finding an element in a render array. I usually use dpm() to print the array, and then expand the options until I find what I'm looking for. On larger arrays that's ...
6
votes
2answers
9k views

What is placeholder_token in html.html.twig for?

Started to dive into Drupal 8 twig, and what better place to start than from the top: html.html.twig But found this: <head-placeholder token="{{ placeholder_token|raw }}"> Here is the change ...
6
votes
2answers
10k views

How and where do I programmatically add a menu to the Navigation menu?

I want to add menu items to the Navigation menu dynamically, depending on certain states (example: user is logged in, etc). I assume I do this in theme_preprocess, but I can't seem to find the var to ...
6
votes
5answers
6k views

How to modify taxonomy term path in the page render array?

I'm trying to change the path of a term before it's displayed on a node page. I'm using this preprocess function in template.php: function bartik_preprocess_node(&$variables) { $variables['...
6
votes
2answers
6k views

Place block region in node template

I am trying to place a block region inside a news content type but it is not rendering. node--news.html.twig: <article{{ attributes }} class="portal-article"> <h1 class="article-title"&...
5
votes
2answers
12k views

Remove or hide the submit button on search block in Drupal 7

I need to do some custom theming on the search block in Drupal 7. Specifically, I need to add a class to the submit button that makes it invisible and removes it from the content flow. So: <div ...
5
votes
3answers
5k views

How to output from custom module without rest of theme

What the proper method of outputting a page from your module without any additional theming beyond your template, for example to make a page that is good for printing? I've tried a few different ...
4
votes
3answers
10k views

Get total row count in views-view-fields.html.twig

How can I get the total rows number in views-view-fields.html.twig template file in Drupal 8? In Drupal 7, I can get it by the following code. $view = views_get_current_view(); $view->total_rows; ...
4
votes
1answer
4k views

How to theme a quiz in D7?

I´m trying to theme my quizzes, but even when I did manage to theme the quiz nodetype (node--quiz.tpl), that template is gone after the "take the quiz" button is clicked. I´ve tried theming the ...
4
votes
5answers
4k views

Additional twig suggestions for menus

Unlike other elements, the base twig suggestions for menus are only "menu.html.twig" and "menu-[menu_name].html.twig". I am aware that I can generate additional suggestions through the hook ...
4
votes
3answers
5k views

CSS for specific pages

How do I add CSS styles for a specific page? For example, I want the <body> background color on a specific page to be different from the background color used on the front page. I've looked ...
4
votes
2answers
3k views

How can I print a field from a referenced entity in my theme?

I'm trying to print a field from an entity reference field - but I don't have a clue how to do it! A bit of background: I've got two content types - master and variation. Variation includes an ...
4
votes
3answers
3k views

How can I assign pages to templates like in WordPress?

I've just made the jump from WordPress to Drupal, and though I love what I'm seeing there's a basic piece of functionality that's obvious in WordPress but is escaping me in Drupal- How does one, for a ...
3
votes
3answers
8k views

How does one theme a panel (or add a style)

I'm using drupal 7 and panels 3. I'm looking for a good tutorial, or tutorial video that describes how to them panels. I understand generally hoe to theme nodes and them fields using the template ...
3
votes
1answer
5k views

In Drupal 8 view.html.twig file how do I access the view content such as individual field title and/or field content?

Using views-view.html.twig as a starting point, I can output {{ rows }}, but I want to loop through each field of each row to aggregate and style them. In Drupal 7, I use dpm(rows) to locate (in the ...
2
votes
2answers
8k views

How do I print core block or views block in node.html.twig?

I'm pretty new to D8, so this might be basic stuff, but I can't find any tutorial how to do it. In Drupal 7 this is the code that outputs core block in node.tpl.php: <?php $block = module_invoke('...
2
votes
1answer
4k views

How to override a theme function?

I'm using LoginToboggan as my login page, and on the login form, it has: "You are not logged in." I want to be able to edit this text, and the admin interface doesn't give an option to do so. ...
1
vote
4answers
5k views

How to access webform elements in webform.html.twig

I'm trying to figure out a way to access webform elements from webform.html.twig. I need to style the form; wrapping some elements and adding bunch of styles all I have in the webform.html.twig is "...
0
votes
1answer
5k views

How to use a field value in Template.php

Im sure this is an easy question, just not for me because of lack of experience with the Drupal preprocess hooks. I am removing the standard "Read More" links from my content. I want the ability to ...
11
votes
4answers
7k views

Candidate page template filename for particular custom content type entry

I'm working on a Drupal 7 website. I created custom content type for works. I have many fields, and some of them are related to page layout like particular page bg for each entry. So I need custom ...
9
votes
2answers
9k views

How remove whitespace on field in twig?

I try to print field value in a node--template.html.twig without whitespace. This field is a select in admin page. Location|Location Achat|Achat This is how my value is print : {{ content....
9
votes
1answer
5k views

Removing all 'stable' theme's CSS from a Drupal 8 custom theme

I would like to remove all CSSs automatically included from stable theme: /core/themes/stable/css/system/components/* I can remove them one by one inside the .info.yml file: stylesheets-remove: - ...
9
votes
7answers
17k views

How to install the commerceguys libraries for Drupal Commerce 2.x?

While installing Drupal Commerce 8.x-2.x-dev on Drupal 8.0.0-rc4, I'm greeted by the announcements: Commerce Price requires the commerceguys/intl library. Commerce Tax requires the commerceguys/tax ...
8
votes
2answers
7k views

why are Twig template variables with markup not being rendered?

In my template preprocess function I have a variable: $test = "<p>this is a paragraph</p>"; and I pass it to my template: $variables['test'] = $test; and output it in twig: {{test}} ...
7
votes
4answers
15k views

Twig get value of field in entity reference

i have a content type "actuality" with a reference to an other content type "event". In "event" i have a "field_date" which i want to print into my "actuality" node. What is the best way to do that ? ...

1 2 3
4
5
20