New answers tagged

0

For override view template, you should override (views-view.html.twig) this is template for all views. If you want override only one specific view then copy code from views-view.html.twig to: [base template name]--[view machine name].html.twig example: (views-view--partners--block-1.html.twig) and override this view as you want


0

After you add your theme suggestion: function discount_theme_suggestions_field_multiple_value_form_alter(array &$suggestions, array $variables) { if ($variables['element']['#field_name'] == 'user_discount'){ $suggestions[] = 'field_user_discount'; } } You need to tell Drupal in this hook you should pick my template by implementing ...


1

You can enable Twig debugging for your site in sites/default/services.yml parameters: twig.config: debug: true Clear cache Inspect element in the browser and you will see the path to the template Copy the template to your custom theme's templates/ directory and adjust the markup


0

When you are allowed making a php file inside the template you could create a core contact form in UI and use a theme_form_alter() hook to prefill the form fields and add custom submit handlers: mytheme.theme use Drupal\Core\Form\FormStateInterface; function mytheme_form_alter(&$form, FormStateInterface $form_state, $form_id) { if ($form_id == '...


0

I added template field-user-discount.html.twig ... in discount module templates folder That's the wrong place to put it. You need to put this in your theme, not in the module's templates folder.


1

The solution came down to replacing "views" with "view" - without the s and "views_page_machine_name" with "all", such that this: entity_print: views: views_page_machine_name : 'theme_name/result-pdf' became: entity_print: view: all: 'theme_name/result-pdf'


3

The raw filter is still fine to use. The filter is not deprecated, only the raw tag. From the Drupal 9 theming documentation: As of Twig 1.x, the raw tag is deprecated in favor of verbatim. Looking at the Twig 2.x documentation, you'll notice that the raw filter is not deprecated. However, in the Twig 1.x documentation for the verbatim tag you can see that ...


-2

If you mean that you wish to rewrite a field (in your case the body field) to something else other than what the user has inserted you can do this. /** * Implements hook_entity_presave(). */ function MODULENAME_entity_presave(EntityInterface $entity) { // If entity type is Article. if ($entity->bundle() == 'article') { // Get the value of the ...


0

You can add a preprocess function like this: function theme_preprocess_file_upload_help(array &$variables) { $description = $variables['descriptions']; // It's where the three objects are, you can manipulate the description. } Or if you want just to add some wrappers around each element, modify the template file-upload-help.html.twig. Currently it ...


0

That is the exact feature of the Book module. Book module overview You can configure which types are allowed to be added as book pages. There is a Block you can place on Book pages to show Book navigation and Previous/Next links (it obeys the Book pages order). Regular Views don't have a feature to center the Pager around a pagination placement. A custom ...


1

Quick-and-dirty way: Uncheck all the boxes to display default classes in Views, and then use a twig template specifically for that views block to write the CSS exactly as you want. You can find the Views twig templates in /core/modules/views/templates. It depends on how you configured the view, but if it's an unformatted block, you want the unformatted ...


1

I opened issue #3190017 Apply table settings to core's forum list table where I added the preprocess plugin and the forum list template with the adjustments to respect the theme settings. You now can change the table settings and revisit /forum to see how the changes are applied. You can simply use the patch via Composer if you want.


0

You probably are confusing {{ header }} and {{ view.header }}. The first prints the header section including the block: views-view.html.twig {{ header }} The second one returns ViewExecutable::$header, an array of handler plugins you have configured in the View. You can try to extract configured string values like in the first example but in case of a block ...


1

leymannx suggested twig debugging, which was super helpful. The solution I came up with was to copy the core/modules/forum/templates/forum-list.html.twig file into mytheme/templates and then modify it to take the table theming elements from the system/table.html.twig file in bootstrap. Here's the end result: {# /** * @file * Default theme implementation to ...


3

You could also do views-view-unformatted.html.twig Note: add the view name if you want to target a specific view, views-view-unformatted--view-name.html.twig {% if title %} <h3>{{ title }}</h3> {% endif %} {% set count = 1 %} {% for row in rows %} {% set row_classes = [ default_row_class ? 'views-row', ] %} {% if count == 1 %} ...


3

One possible solution ist to create two views. One for your featured content (only 1 item or as much you want to feature) and the second one for the rest with an offset. You can set the offset under pager options (items to skip).


0

I had to do it in my website, so I can share a working example : function mymodule_preprocess(array &$variables, string $hook) { if ($hook === 'paragraph' && $variables['paragraph']->getType() === 'your_paragraph_type') { if (is_array($variables['html_attributes'])) { $variables['html_attributes'] = new Attribute($...


2

Based on the comment by @MrD, I found a working solution. I implemented a custom theme negotiator based on this information: Blog post: Dynamic theme switching in Drupal 8 Blog post: Choose your theme dynamically in Drupal 8 with theme negotiation Drupal Answers: How can I programmatically change the active theme? I needed to change the theme for the admin ...


0

Try add in your composer.json file commerceguys lines: "require": { "composer/installers": "^1.2", "drupal/core-composer-scaffold": "^8.8", "drupal/core-project-message": "^8.8", "drupal/core-recommended": "^8.8", "drupal/core-vendor-hardening": "^8.8&...


2

I expected to be able to do it with THEME_preprocess_field, but the data at that point seems to have only the content's markup There are more template variables: field.html.twig: {# /** * @file * Default theme implementation for a field. * * ... * * Available variables: * - attributes: HTML attributes for the containing element. * - label_hidden: ...


0

Drupal 8 collects metadata from any template rendered on a page and puts the result in placeholders of the html template. Unfortunately the html tag in html.html.twig is not placeholdered out-of-the-box: html.html.twig <!DOCTYPE html> <html{{ html_attributes }}> <head> <head-placeholder token="{{ placeholder_token }}"> ...


0

An alternative answer, "don't use composer". We've had pretty good success using a root npm package called "copy-files-from-to" https://www.npmjs.com/package/copy-files-from-to Example package.json { "license": "MIT", "scripts": { "postinstall": "copy-files-from-to" }, "...


0

If your left sidebar only ever display main-menu only, you can create a 2 column layout. Inside the 2 column layout, you can render your main-menu block on the left column with an {% if %} statement. so if there are main-menu items display 3 columns (main-menu(left), body (middle), sidebar(right). else hide the main-menu column and then change your div grids ...


Top 50 recent answers are included