New answers tagged

1

There is no need to write code to get the content type of the viewed node, inside the html.html.twig file: That value is already passed to the template file. logged_in: A flag indicating if user is logged in. root_path: The root path of the current page (e.g., node, admin, user). node_type: The content type for the current node, if the page is a ...


1

You simply can do that without any templating by implementing template_preprocess_html. /** * Implements template_preprocess_html(). */ function MYTHEME_preprocess_html(&$variables) { $node = \Drupal::routeMatch()->getParameter('node'); if ($node instanceof \Drupal\node\NodeInterface) { // Add node type body class. $variables['...


0

In Drupal 8.8, I needed to do this: copy /sites/example.local.settings.php to /sites/default/local.settings.php to enable local development services (this file enable those services by default). copy /sites/default/default.services.yml to /sites/default/services.yml and change twig debug settings i the twig.config: section (starting at line 39): debug: true ...


0

This may not be the most elegant solution, but based upon your preliminary solution and using the output from {{ dump(tableItem }} (the dump is just commented out in the code below; also see code for meaning of tableItem), I was able to extend getting the necessary values in a generic way to output all the values of a given table. Also, after the table, the ...


0

I assume, you can use next modules for your manager (without editing yml files, so no skills required for editing this important one file): CSS Editor This module allows site builders to customize a theme's CSS through the browser, using a rich text editor with syntax highlighting and live preview. Asset injector This module is definitely not a replacement ...


1

Checkbox values are preprocessed so only checked ones you can get in your twig: I think you need to preprocess your field by implementing hook_preprocess_HOOK to add unchecked ones to your variables something like: /** * Implements hook_preprocess_HOOK(). */ function MY_MODULE_preprocess_field(&$variables) { $element = $variables['element']; if ($...


1

$items[] = [ '#markup' => Link::fromTextAndUrl($text, $url)->toString() . ': ' . t('Visit this page to import a book') . '.', ]; $form['mei_marc_list'] = [ '#theme' => 'item_list', '#items' => $items, ]; return $form;


0

You can do this with a display suite custom wrapper. Make sure you are using a display suite layout for the teaser view mode, and then select custom wrappers from the bottom left hand menu. Choose "link to content" from the "add link" drop down.


0

Ok, I kept trying cchen's suggestion and made some discoveries. Twig Since the following did not work, I did not try sub-elements. {{ data.my_address }} Although the whole element does not work (whole elements work with tokens) the sub-elements are still addressable. You can find the sub-element names by looking at submitted form results, under Data (...


0

I was also trying to get the url parameters, but the current path was only returning the path without the parameters. The following solution worked for me in a page preprocess function, I haven't tried with views fields but it should work also. function yourtheme_preprocess_views_view_fields(&$variables) { // Retrieve an array which contains the ...


0

I think you are just overlooking something simple here. The 'multi part form elements' is called a composite element. And it holds an array of values of its subfields. Let's say the composite parent is called 'name', and it has a subfield called first_name, then you can use {{ data.name.first_name }} to get the first name in twig. As for webform ...


0

You can't. This behavior is core functionality from the Block module that's enforcing its data model. Each time you place a block, you're creating a unique Block entity that has a theme property tied to it. Thus, the mainnavigation block entity can't simultaneously be used on the default theme as well as theme3. This is why Drupal defaults to generating $...


0

Markup strips away some tags and attributes. Here is a way to do it. Add a class to your form $form['#attributes']['class'][] = 'crisis'; Add css rule to your theme's css .crisis { display: none; } if you do not have a library and a .css file to use, you need to create them. Define a library in your theme or module in your THEMEorMODULE.libraries....


0

Stupid me. I had .library.yml. and now I see it is .libraries.yml. Once I changed it I started getting the styles coming through. I still have a lot of work to do now to tweak it, but this is a huge step forward.


1

Thank to Hudri : Image styles only work with managed files (uploaded, with entry in DB), not with static assets. Since this is a static asset anyway, just provide the correct size in your module.


4

renderRoot() is for rendering the final result returned by a controller. renderPlain() is for rendering HTML which is not part of a page and is used for other purposes like emails. In your case the correct method would be render(), because this is the only render method which can bubble up metadata to the page. But you don't need to render at all, because ...


0

Here is the answer that worked for me: product.field_accessories[0]['#commerce_product_variation'].get('field_images')[0].entity.fileuri) And I looped over the product.field_accessories to get just the first image for each product


1

Using Twig Tweak you can render blocks inside node templates. For example to render the primary tabs block use: {{ drupal_block('local_tasks_block') }}


1

In page-title.html.twig you don't have access to content variable. according to page-title.html.twig comment section: Available variables are: title_attributes title_prefix title title_suffix So you should implement hook_preprocess_HOOK to passe hide_title to your twig like the following: /** * Implements hook_preprocess_HOOK(). */ function ...


0

You can get it with: {% if node.label %} {{ node.label }} {% else %} {{ page['#title'] }} {% endif %}


0

by default drupal 8 uses commerce-product.html.twig. you can find it from modules/contrib/commerce/modules/product/templates/ and copy and paste it to your template folder in your theme. and to create separate template file for each product type you can add --product type at the end of file name. for example if you have shoes product type then you should ...


1

I'll provide 2 links as an answer, but it has really been answered by others. Write custom webform handler: How to create a custom Webform handler to submit to a SOAP API Use hook_form_alter() to add a custom submit handler. Add a custom submission handler to a form Drupal 8 version of hook_form_alter(): https://api.drupal.org/api/drupal/core%21lib%...


0

After spending two days I found some answer to my similar code. With including and excluding some fields. {% set classes = [ 'block', 'block-' ~ configuration.provider|clean_class, 'block-' ~ plugin_id|clean_class, 'cover-image', ] %} {% set background_image = file_url(content.field_banner_image['#items'].entity.uri.value) %} <div{{ attributes.addClass(...


0

Thanks to Beau for the help. The method is simply $ID = $variables['content']['#paragraph']->id();


0

for your case answer is page--user--register.html.twig, but generally, you can use below twig template naming suggestions: page--user.html.twig page--user--login.html.twig page--user--password.html.twig page--user--register.html.twig I suggest you use page--user.html.twig, for all of these pages.


1

To directly answer your question, yes, you can edit config with the devel module. Install it, then configure it to display the Config Editor. To answer your question pragmatically, I need to point out that making direct edits to configuration on a regular basis is a recipe for disaster. I think you would be better served using the Asset Injector module, ...


0

This doesn't answer the original question, but turns out to be a better solution in my case. You must clear your cache with each change to this function: /** * Implements hook_library_info_alter(). */ function example_library_info_alter(&$libraries, $extension) { // If you have 'stack' as your subtheme, you might have unwanted lightbox assets. ...


0

You can use hook_template_preprocess_default_variables_alter(): https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21theme.api.php/function/hook_template_preprocess_default_variables_alter/8.2.x This hook allows to add variables to all templates which are passed to twig.


0

The book-tree.twig is rendered in its own scope. It does not "know" any of the context it is being rendered in, so it can't tap into the variables from the page twig per se. It only gets the variables you give it. So you could implement a THEME_preprocess_book_tree(&$variables) hook to add it in. $variables['page_nid'] = // your code here will make ...


0

I think it's better to use hook__theme_suggestions_HOOK_alter: Something like this: /** * Implements hook__theme_suggestions_HOOK_alter(). */ function MYTHEME_theme_suggestions_item_list_alter(&$suggestions, $variables) { $suggestions[] = 'item_list__' . str_replace('-','_',$variables["attributes"]["id"]); } Just make sure that in your ...


1

To override templates for one view page or block, i guess you should add another suggestions like views-view-fields--VIEW_NAME--DISPLAY_NAME, to do so you should implement hook_theme_suggestions_HOOK_alter. here is an example for views_view_fields hook: /** * Implements hook_theme_suggestions_HOOK_alter(). */ function ...


1

Theme suggestions like that do not work on node titles, out of the box. You could theoretically add your own suggestions based on node title, but it seems like a very bad idea to me because editors can change titles at will, which will immediately break the correspondance to the templates in your file system. If you really want to target an individual node,...


-1

Hey i think you need to override only one node template, If i am not wrong then,you need to override only node page for eg.you created 'Promotion' node page and in your case your 'Promotion' page node has eg. 101. According to that node '101' will be override. eg. node--101.html.twig or node--promotion.html.twig Note - You don't need to create ...


1

Yes. The pattern will be something like views-view-promotions--display_name.html.twig See https://api.drupal.org/api/drupal/core%21modules%21views%21views.theme.inc/group/views_templates/8.2.x Also, I recommend you activate Twig debugging (https://www.drupal.org/docs/8/theming/twig/debugging-twig-templates) to see actual suggestions.


0

Assuming you're using the default field definitions installed by the standard profile, what you want is the status property of the comment field of the node, which is accessible in twig via node.comment.status. {% if node.comment.status == 2 %} {# comments are open #} {% elseif node.comment.status == 1 %} {# comments are closed & visible #} {% ...


0

Drupal takes specific template file for the page if present. page--front.tpl.php will be used only for the home page (or front page). If you want a specific template for your page with all the regions as in page--front.tpl.php, copy front page template and rename it to page--{page-path}.tpl.php. Clear the cache. Now the page you want will display all the ...


0

This should help function MYMODULE_theme_registry_alter(&$theme_registry) { $extension = '.html.twig'; $module_path = drupal_get_path('module', 'MYMODULE'); $files = file_scan_directory($module_path . '/templates', '/' . preg_quote($extension) . '$/'); $fs = \Drupal::service('file_system'); foreach ($...


Top 50 recent answers are included