TransWikia.com

Use twig to style a specific block (unformated list)

Drupal Answers Asked on November 15, 2021

I have a block showing a unformated List of fields. Now I would like to use twig to style that block.

I am able to use block--views-block--blockname-block.html.twig to do the outer styling. But I could not get the fields out of the content.

2 Answers

Ok I got it. I've already overwritten form templates to add a template suggestion that included the form id. Here's the code :

function hugo_theme_suggestions_form_alter(array &$suggestions, array $variables) {
    if (isset($variables['element']) && isset($variables['element']['#type']) && $variables['element']['#type'] == 'form') {
        $original_theme_hook = $variables['theme_hook_original'];
        $suggestions[] = $original_theme_hook . '__' . str_replace('-', '_', $variables['element']['#id']);
    }
}

Maybe you could reuse this piece of code changing the form by the view, something like YOURTHEME_theme_suggestions_view_alter

Answered by Hugo on November 15, 2021

Not sure to understand what you mean...

Do you want to customize the fields that appear in your block?? If so, Drupal normally provides you with available twig hooks you could use. Yours would probably be field.html.twig.

Exemple : you can customize a menu with menu.html.twig and then customize the links in that menu with links.html.twig

Answered by Hugo on November 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP