1

I am trying to theme a block from my view. I have a view called slides and it is creating a block. I have a template file I want this block to use. I have looked at the documentation for themes and the pattern to follow is

views-block--<viewname>.html.twig

or

block--views-block--<viewname>-displayid.html.twig

I can't find displayid for my block so I am trying to get that first option to work, but No matter what I do my block wont seem to take on the template I have written.

my template is named

views-block--slideshow.html.twig

What am I doing wrong with my names?

1

In your development.services.yaml file set twig debug to true and disable the cache by setting value to false.

After that you will see theme suggestions by inspecting element in browser.

  • If you can't find the file, just let me know, I will help you. – Arthur Baghdasaryan Apr 7 '18 at 19:28
0
block--views-block--slideshow-block-1.html.twig

This is what it supposed to be. When configuring the block it gives the entire file name and I just needed .html.twig on the end of what the block name is in the configuration page for the block.

  • 1
    somehow when I copied and pasted I missed the block-- part. – No Sssweat Jun 5 '15 at 19:51
0

To quote drupal.org

Also one more example with Views, if you have a block created by views with a view name "front_news" and display id "block_1" then the theme hook suggestion would be: block--views-block--front-news-block-1.html.twig (notice, when you have underscores in a display id or in a view name - you have to transform them in to a single dash)

Well in drupal 7 the "display id" is the machine name under "other"

enter image description here

Lets pretend the above picture is your Slides view.

Assuming its the same for 8, then it would be block--views-block--slides-block.html.twig (for the above picture)

If your machine name is block_1 then it's block--views-block--slides-block-1.html.twig

0

In Drupal 7 under ADVANCED you just need to click the theme information link and it will show you all the template names.

enter image description here

In Drupal 8, you're are expected to turn on twig debug and see the template file suggestions. See Locating Template Files with Debugging

  • I cant find anything like this in d8 – BrandenB171 Jun 5 '15 at 15:23
  • In your edit view, Did you click on ADVANCED? (located on the far right) – No Sssweat Jun 5 '15 at 15:27
  • Yeah the last thing on the list is CSS Class – BrandenB171 Jun 5 '15 at 15:51
  • Dang, I guess Drupal 8 is different. – No Sssweat Jun 5 '15 at 15:53
  • drupal.org/node/2354645 yeah according to this the naming convention should just allow it to override the template – BrandenB171 Jun 5 '15 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.