New answers tagged

0

I found a couple of ways to achieve it, posting here, but I'm open to better/cleaner ways. I'm especially unhappy in my answers with the way to access the tag name - seems so overly complicated trying to get the raw name?! Both code blocks live in a mytheme_preprocess_node(): Answer 1: create a new variable with all the tags in it: <?php $allTags = []; ...


2

elements is the variable name defined in theme_hook() to hold the renderable elements (for the node this is the entity build array). Preprocess is then responsible to prepare variables for rendering, like content. If your goal is to modify the template output then check first which variables are actually printed. In a node template it doesn't make sense to ...


0

You have to customise how TB Mega Menu works. In your_theme.theme you must add: function yourtheme_js_alter(&$javascript) { $javascript['modules/tb_megamenu/dist/js/frontend.js']['data'] = drupal_get_path('theme', 'your theme') . '/js/frontendcustom.js'; } In your js folder of your theme you must add a custom file frontendcustom.js. The file is ...


0

this is the code I used at the end (don't remember how I get it, but I remember that KINT debugger helped me a lot): {# start to cycle #} {% for immagine in content.field_immagine_colonnine %} {% if immagine['#item'].target_id > 0 %} <div class="imagetext"> <img alt="{{ immagine['#item'].alt }}" ...


1

If you wish to solve this inside a twig template you can use the following: <img{{ attributes.addClass(classes).removeAttribute('width').removeAttribute('height') }} /> This should be available since Drupal 8, see following issue: https://www.drupal.org/project/drupal/issues/2325517


-2

According to the dump of content which is shown ahead I would try to print a single field in the twig template like this: {{ term.fields.field_logo.values }}


1

The page template lists under General Utility Variables the is_front variable: {% if is_front %} {% include '@themename/homepage.html.twig' %} {% else %} {% include '@themename/innerpage.html.twig' %} {% endif %} This should solve the problem, even if you visit the page by different URLs. You can avoid that as well, the Redirect module redirects ...


0

Use template from a module You have to specify the template in hook_theme() with the correct base hook. Here is example for hook 'node': function MY_MODULE_theme($existing, $type, $theme, $path) { return [ 'node__custom-type__full' => [ 'template' => 'node--custom-type--full', 'base hook' => 'node', 'path' => ...


0

Thank you sonfd this my code now and it's working! {% for item in items %} {% if menu_level == 0 %} {% set item_classes = [ 'menu-item-edot', item.is_expanded ? 'dropdown', item.is_collapsed ? '', item.in_active_trail ? 'is-active', ] %} <li{{ item.attributes.addClass(item_classes) }}> {% elseif ...


0

Use an array: $session = \Drupal::request()->getSession(); $allowed_temp_files = $session->get('anonymous_allowed_file_ids', []); $allowed_temp_files[$file->id()] = $file->id(); $session->set('anonymous_allowed_file_ids', $allowed_temp_files); Example from /core/modules/file/file.module


1

There was a caching problem that had nothing to do with the template itself. Not sure exactly what happened but I turned off MAMP, did something else for awhile, came back and it was working fine. Thanks!


0

Since google_tag started using containers, the format has changed a bit for the GTM settings, so you should now use the following: $config['google_tag.container.label_machine_name_here']['container_id'] = 'GTM-000000'; label_machine_name_here is the machine name from whatever you called the GTM container in the module settings. You can use the above method ...


0

In the node template: {{ content.field_image[0]['#attributes']['alt'] }}


0

You have entity values at hand $element = $variables['element']; if ( $entity = $element['#object'] ) { dump ($entity); exit; }


0

I'm not sure if this will answer your question as you are stating that you want to render a region in the menu template. You can't do this in the traditional sense but you can use Twig Tweak to render blocks pretty much in any template assuming you have the right context. See their help pages for good documentation on how to do this. Twig Tweak Cheat sheet ...


0

With the help of Twig Tweak Module, you can print subparagraphs content in the right context : {{ drupal_field('field_paragraph', 'paragraph', paragraph_id) }} Here is the example documentation.


1

Simply go to Structure > Content types > My content type > Manage display. https://example.com/admin/structure/types/manage/page/display. There you re-order fields displayed in your default frontend theme with a couple of clicks, export config, done. For deployment git push the exported config files, on prod git pull it again and now import config, ...


1

Your field_logo has got a list (array), where is your logo. I would try {{ content.field_logo[0] }} If you want some helpful forum with more info about references (and entities for nodes as well) look there: https://www.drupal.org/forum/support/theme-development/2015-12-16/entity-reference-values-in-twig-template


0

In your node template say "node--article.html.twig" you can reorder links and body as follow. <div{{ content_attributes.addClass('content') }}> {{ content.body }} {{ content.links }} you can also use {{ kint(content) }} in your template to view other things as follow.


2

{{ content }} contains everything, you can be more granular and replace it with, for example: {{ content.title }} {{ content.body }} {{ content.field_name }} {{ content.links }}


0

I just added field type => date and its showing the date pop $form['start_date'] = [ '#type' => 'date', '#title' => $this->t('Start Date'), '#description' => $this->t(''), '#maxlength' => 64, '#size' => 64, '#required' => true, '#attributes' => [ 'class'=> [ 'user-form-startdate' ] ] ]; $form['...


1

@khummari's answer didn't work for me. However, I was able to adapt it. I continued to use field--taxonomy-vocabulary-1.html.twig to theme the tags as I desired. I then modified node.html.twig as follows. I used {{ content.taxonomy_vocabulary_1 }} to render the tags in my desired location. To prevent them rendering in their default location, I rendered the ...


0

In node--article.html.twig override in your theme's template directory as follow Then override the tags field twig template as follow following should be the result


1

Add "view content" & "edit content" link in view as follow Then put views-view-table--articles.html.twig file in your theme's template directory and get fields as follow. <div class="example-template"> {% for row in rows %} {% set titletxt = '' %} {% set viewnod = '' %} {% set editnode = '' %} {% for key, ...


0

Well my solution for this, is to make a function on a custom module and print out my code directly to the page. function custommodule_form_alter(&$form, $form_state, $form_id) { global $user; if($form['#form_id'] == "user_profile_form" && in_array('administrator', $user->roles)){ echo $form['form_id']['#value']; print ...


2

Drupal stores times always in UTC, never in local time. Also Unix timestamps are by definition in UTC. You can convert a local date string to a timestamp by creating a \DateTime object: $timestamp = (new \DateTime('2021-12-31'))->getTimestamp(); Which is using the default PHP timezone or by specifying your own time zone: $timestamp = (new \DateTime('2021-...


0

I had the error still appearing no matter what. Drupal\Core\Extension\Exception\UnknownExtensionException: The module twig_food does not exist. Finaly i found this command working: drush cdel core.extension module.twig_food


Top 50 recent answers are included