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!

Related Questions

“&” displaying as “&”

1  Asked on February 28, 2021 by mohk


Confirmation pop up on login submit

1  Asked on February 22, 2021 by vipin-p


Override a node page of specific content with views page

1  Asked on February 21, 2021 by hkguile


Hide Alt and Title for image field

2  Asked on February 20, 2021 by moto


How do I update from 9.0.10 to 9.1.0?

1  Asked on February 19, 2021 by user101999


Adding fields to content type edit form (not to the node itself)

1  Asked on February 18, 2021 by chris-riddell


Uploaded images in theme settings is going to be lost

3  Asked on February 13, 2021 by saidbakr


How to delete a large amount of nodes effeciently during cron?

1  Asked on February 12, 2021 by athakhan


Composer updates .htaccess file when updating

3  Asked on February 11, 2021 by albertski


How to print the Views title in page.tpl.php?

3  Asked on February 10, 2021 by szymon-panecki


May I use Bootstrap-CDN on Subtheme for production site?

1  Asked on February 7, 2021 by leelandra


Alter Webform email body

1  Asked on February 6, 2021 by lus


Ask a Question

Get help from others!

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