Hi,

Anyone knows how to theme views? I don't like the way views display my data.

Many thanks in advance

Comments

johnlee80’s picture

Hi,

Well, you have a few options.

1. You can do some styling right within Views under the Basic settings section.
Next to Style, click on Unformatted (assuming this is selected now) and choose from one of those styles.

2. The other option is throw that view into a block, then use Block Theme Module to select a theme for that block. You would need to first style the block by creating your own customblocktheme.tpl.php file then select it in the module. There is a link to a tutorial that was very helpful for me to understand the process.

Hope this helps.

sp_key’s picture

Johnlee,
Many thanks. I'm following your advice. The video was super and the process very clear!

Adam S’s picture

How decent are you HTML and CSS skills?

I took this from openpublish this file is views-view-unformatted--block.tpl.php. Which he made by copying the file from views into the theme directory that is being used and renaming it with a name that views gave him to override the views file. I made a screen shot of the the area in views that gives you this information. At the bottom of the views options list it says themes. Click on that and you get the dialog box with all the options of potential template names -- the one being used is bold (opps, I didn't grab the correct one, but it shouldn't matter explaining it). The first one in the list is the default and you can name the file you move (or make from scratch if your feeling brave) to your sites/all/theme/[template folder] directory with any of the others in the list the the right of the default name. They will override the default. http://thechefsgalley.com/assets/views_example.jpg

If you enable the devel module and put dsm() function into the template you can get a list of all the variables that are available to you. Then you can access the information in those variables to further inrich the content on you page by <?php print $[your variable] ?>.

Let me know how it goes and good luck!

WorldFallz’s picture

See Views 2 theming as well as views advanced help.

sp_key’s picture

Hi, I had already done so - apologies for not mentioning - but I thought it was very complicated and not easy to follow.
Hopefully the block theme module will be easier to follow, otherwise back to advanced help!
Many thanks all for your time and help!

sp_key’s picture

Hi,

I'm not sure how to make this work for me!
According to the video tutorial you duplicate a block.tpl.php file and add a css class to it however, my template is missing a block.tpl.php file and I don't know how to write one.
I tried copying the default block.tpl file from the default drupal theme but it didn't work.

I also tried a different approach following WorldFallz' advice. According to the views 2 theming document, you create the template files using the code from either the display or row style outputs. I then added the class (from previous approach) but no success.

I've waisted 2 days on trying to style a view my head is going to explode!

Can someone please give me a hand?

Sp

WorldFallz’s picture

You can copy the block.tpl.php file from the system directory into your theme directory and it will work. I do it all the time-- hundreds if not thousands of themes do it. It does work. You need to 1) have a block.tpl.php file even if you only want to use a suggestion (ie block-left.tpl.php) and 2) clear the theme registry.

Views 2 theming also works-- many many many sites theme views. Make sure you click the "rescan template files" button. The first thing i usually do is create the template file I'm trying to use and place a single line in it (ie "THIS IS THE CORRECT FILE"), to verify the file is named correctly. Then, once you verify that, you can start your theming code.

The devil is in the details-- I see a lot of people in the forums complaining that this or that "doesn't work"-- it's usually because they either didn't read, only skimmed, or missed an important step from the documentation. Verify that you've followed every step correctly. And don't mix methods (ie theming both block.tpl.php and views-view--block.tpl.php)-- verify one thing works before moving on.

sp_key’s picture

WorldFallz,

First of all, many thanks for your time and persistence in trying to help me.

This is exactly the process I'm following which has no results whatsoever.

1. Created a theme in site configuration/Block Theme (redblock|Red Block)
2. Copied the block.tpl.php file from the system directory to my theme directory (AD Novus - http://drupal.org/project/ad_novus)
3. Renamed the file to blocktheme-redblock.tpl.php as specified in the README file of the block theme module
4. Added a class in the block.tpl.php file (...print $block->module ?> redblock">)
5. Cleared all Cache from Site performance
6. Selected the "Red Block" template for my block
7. Added the following class in my CSS file

.redblock {
background: red;
}
8. Refreshed broswer a hundred times clearing the cache as well

I have also tried:
a) renaming my blocktheme-redblock.tpl.php file to block.tpl.php file which broke my site until I deactivated the blocktheme module, deleted the file and reactivated it
b) copied my template file in the views/theme directory and
c) moved my class from my child to my parent css.

I really can't see where I'm making the mistake. This is exactly what the tutorial instructs.

Any thoughts will be greatly appreciated.

Many thanks
Sp.

Adam S’s picture

They have more videos at mustardseed media. Try this one http://mustardseedmedia.com/podcast/episode23 .

WorldFallz’s picture

3. Renamed the file to blocktheme-redblock.tpl.php...

Do you now have both block.tpl.php AND blocktheme-redblock.tpl.php files in your theme directory?

Also I didn't catch the addition of block theme module-- I've never used it so I can't help you there. The comments I made apply to theming blocks the standard way.

sp_key’s picture

No, I don't have both. Just the redblock template.
I guess I need to try more with the standard way which I was trying to avoid as I preferred a more transparent way.
I'll come back if I need more help on this.

Many thanks

ps: I'll watch the rest of the video tutorials - thanks for this suggestion also.
sp

WorldFallz’s picture

As I mentioned above, you must have both. Derivative suggestions will not be detected without the base template. The devil is in the details... ;-)

sp_key’s picture

Ok, sorry - I'll do that again then.
I was going as per the blocktheme video tutorial which I promise you did not mention such a thing.