By Codium

2011-09-17 13:52:22 8 Comments

There is a lot about theming custom blocks, but what about blocks created by views?

My views block has id: block-views-posts-listing-block,

I try many ways for naming template file, ex: block--block--views-posts-listing-block.tpl.php, but I can't find correct file name.


@SwingingTom 2017-09-02 11:12:39

You are on on D7 >= 7.33 you could display theme_suggestion directly in the page as HTML Comments using :

in settings.php

$conf['theme_debug'] = TRUE;

Here is the complete documentation 2016-05-25 11:45:02

For blocks inside panel panes, the solution provided by noTxt and other is not working. The syntax would then be (no underscores!):


Thanks to user3074436 for providing the $conf['theme_debug'] setting in order to figure out this exceptional theme overriding case

@No Sssweat 2016-04-29 02:06:00

In Drupal 8

enter image description here

The fields template would be:


@Pierre.Vriens 2016-08-20 08:43:46

This question was about D7 ... Why the Drupal 8 in your answer?

@No Sssweat 2016-08-20 10:18:40

@Pierre.Vriens since question is popular in views (not the module), I figured I should add a D8 version answer in here.

@Pierre.Vriens 2016-08-20 18:38:32

Now that's an interesting idea ... How about doing the same for these +21K questions also then?

@No Sssweat 2016-08-20 23:47:14

@Pierre.Vriens most of those are not popular.

@Codium 2016-08-21 09:21:56

8 tag added, nice ;)

@noTxt 2012-01-31 21:47:22

For those seeking the answer in D7, according to Theme Developer(aka devel_themer), you can create a tpl override for a view's block using the convention:

block--views--{view's machine_name}-block

Therefore in the example give you will get

block--views-- post-listing -block.tpl.php

Without the spaces (I couldn't edit this properly to allow it all to be inline.

@Nevos 2012-06-16 15:25:01

I confirm noTxt is correct, go to the block section, and edit the block, the url should show you the view's block name with underscore, my_view_name-block. replace the underscores so my-view-name, and use this format: "block--views--my-view-name=block.tpl.php"

@Nikit 2013-04-17 02:24:51

Yes, this is more correct answer, so: block--views--VIEWNAME-MACHINENAMEOFDISPLAY.tpl.php Attention to single dash before Machine name! Machine name = by default it's named as block, block-1 and so on, but you can rename it in views UI.

@user3074436 2015-07-22 14:01:26

The file name patterns describe above works UNLESS your view name + display name is longer than a certain amount of characters!! I was caught by this and could not find why a template file ending in ...block.tpl.php was working and the following display ...block-1.tpl.php was not working.

It turns out that Views replaces the machine name with an MD5 hash if the name is too long. If you want to be sure of the template name you should be using, add $conf['theme_debug'] = TRUE; in your settings.php and then look at the page source. if you find something like block--views--d131dd02c5e6eec4.... you'd better shorten the machine name of the view (if you manage do to that... It's not the human-readable name). Or else you need to use a template file with that silly name.

see also

Views Block's machine name is being "hashed" (?)


@Егор Малыгин 2014-07-27 20:00:56

Check this page, and information about underscores which views uses:

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--front-news-block-1.tpl.php (notice, when you have underscores in a display id or in a view name - you have to transform them in to a single dash)

@Arindam 2013-06-07 13:02:30

block--views--[view-name]-[display-name].tpl.php should be changed to block--views--[view-name]-[machinename].tpl.php.

You will find the machine name from your views advanced section where it is written other

@TourTools 2012-09-14 22:46:32

At the end of half an hour changing tpl names, here is my final conclusion:


[view-name]-[display-name] part can be found like noTxt said or joining with a '-' the id name of the view and the id name of the view display, the -block at the end isn't correct.

@cigotete 2011-09-17 16:39:39

Edit your view. and Under the "Advanced" settings of your Block details, click on "Theme: Information". A list of options of template files will be displayed.

for example, if your block has a name "posts listing", see possible names listed by "Theme Information" option:

* Display output: views-view.tpl.php, views-view--posts-listing.tpl.php, views-view--default.tpl.php, views-view--block.tpl.php, views-view--posts-listing--block.tpl.php
* Style output: views-view-unformatted.tpl.php, views-view-unformatted--posts-listing.tpl.php, views-view-unformatted--default.tpl.php, views-view-unformatted--block.tpl.php, views-view-unformatted--posts-listing--block.tpl.php
* Row style output: views-view-fields.tpl.php, views-view-fields--posts-listing.tpl.php, views-view-fields--default.tpl.php, views-view-fields--block.tpl.php, views-view-fields--posts-listing--block.tpl.php
* Field Content: Title (ID: title): views-view-field.tpl.php, views-view-field--title.tpl.php, views-view-field--posts-listing.tpl.php, views-view-field--posts-listing--title.tpl.php, views-view-field--block.tpl.php, views-view-field--block--title.tpl.php, views-view-field--posts-listing--block.tpl.php, views-view-field--posts-listing--block--title.tpl.php 

for example: your block has the name posts listing, and has style unformatted, then "Theme Information" suggest the name views-view-unformatted--posts-listing--block.tpl.php (this is only one of several names). you can copy the original views-view-unformatted.tpl.php template file (located in /modules/views/theme) to your current theme directory, and rename this file with the name suggested :views-view-unformatted--posts-listing--block.tpl.php. then make the changes inside your template file. If this template does not allow make your wanted changes, seek other templates according your needs.

In the end, if you add a new template, rescan template files list:

Important! When adding, removing, or renaming template files, it is necessary to make Drupal aware of the changes by making it rescan the files on your system. By clicking "Rescan template Files" button you clear Drupal's theme registry and thereby trigger this rescanning process. The highlighted templates (in your template list above "Rescan template Files" button) will then reflect the new state of your system.

Also Theme Developer Module suggested by Oswald could be useful to detect possible template/s to change specific elements according your criteria. I do not recomend this module enabled in productions enviroments (in my case, even I have disabled the module in test enviroments, because seems to have conflicts with views, but when it has been necessary, has been very useful)

@Codium 2011-09-18 13:41:55

No it doesn't help with theme views block output. It's only for theme view content, but I want to theme block that wrap my view

@cigotete 2011-09-18 16:12:05

Hello, please review again the list of templates indicated by "Theme Information" in View->Block settings, there are several templates that end with --block in his name. Remember reescan templates, and remember put the template inside directory of your current theme (copy the selected template from modules/views/theme). the template must have the name suggested by the "Theme Information" list. It works.

@cigotete 2011-09-18 16:33:22

@drupality, I have added an example with steps to review the process, please review in "for example" paragraph, in the answer.

@Codium 2011-09-19 10:56:22

Thanks but I can't remove default div class="content" wrapper with that too. I can only alter html created by views

@cigotete 2011-09-19 15:28:39

@drupality, regarding remove default div class="content", you can overwrite the specific CSS rules that are making problems with other CSS rules (inheritance precedence). Or also you can add classes to your view to change this. Or also you can use !important CSS declaration to give more precedence to your rules. Or also you can assign classes inside your templates to control with more detail.

@user3337 2011-10-12 19:56:48

@moon.watcher I think you misunderstand. Ending the template file with "block" doesn't affect the theming of the block itself. It makes that template file specific to the block that the view is outputting (as a view can output multiple blocks from the same view). The themed content from the view is output to the block theming engine, and is wrapped in the markup provided by block.tpl.php. What drupality is trying to do (as well as I am) is change the theming of the block itself.

@Matt Fletcher 2017-07-09 20:48:17

This answer completely misses the point, and yet is highly upvoted and even the accepted answer, but why? Ignore it and go to noTxt's answer if you want the solution for the actual question posed, about the block that contains the view not the view itself. It's weird really that the developers even left that out of the views theme information.

Related Questions

Sponsored Content

1 Answered Questions

[SOLVED] Views block template print individual field from content

1 Answered Questions

[SOLVED] Views Template for first Block being applied to all

  • 2018-04-11 18:58:31
  • Travis Johnston
  • 10 View
  • 0 Score
  • 1 Answer
  • Tags:   7 views theming

1 Answered Questions

[SOLVED] Trouble getting a drupal 7 view template to render for a machine readable block

  • 2017-09-29 13:59:07
  • Gavin Bruce
  • 16 View
  • 0 Score
  • 1 Answer
  • Tags:   views theming

1 Answered Questions

[SOLVED] Custom template for view with block display in a page

2 Answered Questions

[SOLVED] How is a theme template file picked up?

  • 2016-01-19 04:35:39
  • anru
  • 1416 View
  • 1 Score
  • 2 Answer
  • Tags:   theming 8

1 Answered Questions

[SOLVED] Template file for Views exposed filter block

  • 2015-05-23 15:23:54
  • Patrick Kenny
  • 1616 View
  • 1 Score
  • 1 Answer
  • Tags:   views theming blocks

2 Answered Questions

[SOLVED] Template name convention for view mini pager

  • 2012-07-13 18:07:00
  • Geeo
  • 1224 View
  • 1 Score
  • 2 Answer
  • Tags:   7 views paging

1 Answered Questions

[SOLVED] Load a views block in a tpl file with his custom template

  • 2012-02-10 11:56:58
  • dazz
  • 786 View
  • 0 Score
  • 1 Answer
  • Tags:   views theming

Sponsored Content