Views Theming

On this week's podcast, Bob addresses something that lots of you have asked about in the past few weeks: Views theming! He'll talk about when and when not to use Views theming and what, exactly, you're trying to accomplish when you use it. All on this week's Mustardseed Media video podcast!

I notice that you use a local machine configuration to do these podcasts. I have experimented with different packages, such as XAMPP, WAMP, etc and have had no luck in getting Clean URLs to work with Apache. Perhaps you could do a video podcast describing how to set up a configuration similar to the one you use for your podcast. Thanks!
Hey Cole.... Funny you should mention it...I just saw your post over at Geeks & God and I was thinking the same thing. The problem is, on a Mac, it's basically:
  1. Install MAMP
  2. Done!
Let's discuss your issue over at G&G and see if we can resolve it there. If I find I'm taking some steps for granted, maybe I'll turn it into a podcast episode.
I appreciate the insight into changing the themes in views. I didn't realize this was possible, but if you wanted to simply change the style of the title wouldn't that be better handled in CSS? Perhaps I'm being too picky but would it have been a little better theming to add a div tag to the template file and then alter the item with the CSS styling? Thanks for the food for thought!
Hey Tim.... First, adding an h2 was a totally random example...so it may or may not be appropriate in the situation. But that being said: What you have to remember is that adding an h2 is not about how the content LOOKS. Heading tags are about architecture and a proper data model, not about theming or design. You can make every h2 on your site look different if you wanted to...that's not what an h2 is used for. Heading tags should be used to properly architect the site, not be used for styling. So, if you just wanted that text to look a certain way, sure..just use CSS. But if you want it to be a heading in your architecture, you'd use an h2 (or other heading tag). Make sense?
Yes that makes sense. I think I was too locked into style in my head to see forest beyond the tree.
Hey Bob - Thanks for the video. I was wondering if you could expand a bit on that $output variable from the View row theme. As we noticed in the rendered source code, there's a span showing up there around the content of the field (in the example). Suppose I wanted to go in there, grab the same data out of the field, but get rid of or otherwise change that span tag? You mentioned print_r is the way to look into that, though I've always had some trouble grasping how to use that properly (e.g. what to put in it, and how to properly call up what I learn from it if I do happen to get it to show the right data). You mentioned talking about it before, so if that'd do the trick feel free to just refer me over to that instead of re-explaining (I wasn't sure where that info was). Thanks brother! :) Oh btw - just got home tonight from a Michael W. Smith concert... he had a full orchestra on the stage, which was beyond cool :D
I have followed these steps - and saved a new tpl.php file based on the list in the "Information" section under my view. However, click on the Rescan button yields absolutely no results - it simply keeps the "least specific" (first) one there. Any thoughts as to why this might be occurring, and how I can fix it?
Just to knock out the possible easy answers... 1) Make sure you are saving these into your own theme's folder (I've seen people occasionally assume they go into the Views module folder, so just mentioning this). I "think" it has to go in the root of your theme's folder (yourthemename) and not into a sub-theme folder, if you're using sub-themes. 2) Double check that you don't accidentally have a space at the front of the file name, and that your code editor correctly saved the "double extension" of filename.tpl.php 3) Probably not the case, but clear Drupal's theme cache at Site configuration > Performance. And clear Views cache from its Tools menu. 4) When you go to the Theme information settings, make sure you've first selected the correct Display of the view that you want to theme. The filenames may be different between each Display. What is the name of the template file you've saved? Hope this helps, or else Obi-Bob Kenobi may be your only hope :D
one way that I use views theming is to trim the output of field(s) to a specify charactor lenght using a php function. in your template.php add function neat_trim($str, $n, $delim='...') { $len = strlen($str); if ($len > $n) { preg_match('/(.{' . $n . '}.*?)\b/', $str, $matches); return rtrim($matches[1]) . $delim; } else { return $str; } } I mostly like to select my theming based on the view display title and field name, instead of just field name because I want the option to set custom theming per view display+field(s). So in your views-view-field--VIEWSdisplayTITLE--body.tpl.php add <?php $string = neat_trim($output, 150); print $string; ?> The above will trim output to only 150 charactors while keeping words intact and adding "..." at the end of the trim. There are unlimited ways to theme your view's $output this is 1 of a million. now for an exercise add a $node_link in replacement to "..." in the template.php neat_trim function.
Hi Rob! Hey, I just wanted to put in a request for a video podcast on using / understanding the Relationship feature of Views 2. If I had known about how to use it, it would have saved me a week of headaches trying to solve a problem. The fact is, there really is not very much "in-depth" (detailed descriptions of features / usage, etc.) information about how to use some of the stuff in Views 2. For a description of the problem, and the solution see the following thread ... http://geeksandgod.com/forums/dynamic-website-forums/all-about-drupal/no... Thanks for all you are doing! It's helping this lowly drupaler!! :) Greg
I'm in the same boat as Josh. When I add a specific template, it's ignored *unless* all of the less specific templates also exist in my theme folder. My understanding is that Drupal is supposed to look first for custom templates in the theme folder, then look for stock templates in whatever module it needs at the time. Somehow, that doesn't seem to be happening for me. I'm using Drupal core 6.9. Any ideas?
Hey Rob, I'm building a site for a client and I'm trying to display the 1pixelout player in a view created from filefield/swftools nodes. I've tried wrapping the views theme output with swf: <?php print swf($output); ?> However, all I get is 'No player is configured to play a series mixed media files.' error and the following text where the player should be: You are missing some Flash content that should appear here! Perhaps your browser cannot display it, or maybe it did not initialise correctly. I'm assuming there is more to it with a views theme than a node theme. Any thoughts? (D6, Views2)
Poieo: When theming in Views, $output doesn't usually contain anything directly usable...instead it's a big clump of html and content all spit out together...so you can't really just use it inside a function like this. What you need to do is get the filepath of the audio file from the view and put it in the swf function. This isn't super easy, but it's doable. You need to use views Relationship feature to expose the file's information, then use that in the View. For info on this, see the last comment on this post over on the geeksandgod.com site.
Bob, That did it...thank you for your help.
First off, the Rescan Template Files Button does not work in my Drupal 6.9 version either. It grabs the correct template file, but does NOT highlight the name of the template file actually being used. Secondly, there seems to be an abundant supply of the basic view demos on the web. Are there any plans for a more advanced demo? What if you need total control of the output of the view. From what I see in all these view demos, the view seems very limited the way you can output your view fields. Do you really need to output all the fields in one row? What if I wanted to do something like this: some javaScript view-field1 [some more javascript] view-field2 [more javascript] view-field3 some html

view-field4

more html Is there a way to control the output of a view in this way, field by field?? Views seem so restrictive in this way!! Any suggestions? Thanks for the podcast.
hi, maybe it will be useful for someone - you must have administration theme the same as theme of your site. My conf.: D6.10, Views2
Hi Bob, I am having problems getting views2 to display the one pixel out audio player. My problem is exactly the same as described in this comment: http://geeksandgod.com/forums/dynamic-website-forums/all-about-drupal/no... only I am trying to get views to play an audio file via 1 pixel out rather than display a PDF file link. I have tried everything you suggested above but still cannot get views to detect the audio file. I have searched for related topics online and have come up empty handed. Do you have any suggestions or pointers toward a solution to this problem?
Answered my own question using the following code: <?php print swf($row->files_node_data_field_audio_file_filepath); ?>. Follow all the steps outlined in this post: http://geeksandgod.com/forums/dynamic-website-forums/all-about-drupal/no... but swap the code out for the code I have supplied and place it in the "views-view-field--{YOURVIEWNAME}--field-audio-file-fid.tpl.php" template available under "theme Information". After this, in order to hide the "File Path" that shows up as a result of adding the File Argument and then adding the File Field, click on the File Field in the "Field" section of "Views Interface". in order to edit it. Then, Check the "Exclude from display" check box and save. This will then hide the "file Path" display, but allow the file-path to remain hidden so that the "One Pixel Out" player can function. Hope this makes sense.
He is effectively doing what you say :)! The h2 tag is effectively a div class. In his CSS doc he will have a h2 specified e.g.: h2 { insert styling here } He could have created a new div id/class but why bother? He has a class (h2) already specified which he can use.
thanks so much for another really helpful show, you do such a good job of breaking it down into plain english, and explaining each step. I'm such a fan!
Seems every podcast of you is so useful for me,pls keep it on : )
exactly what I needed!! Cheers
bob, u r amazing! i learnd more in your screencast as in books! <3 nice greets from middle europe! :)
Hi Bob just watched your Views Theming podcast and I must say its very good. Unfortunately a little too vague for what I am trying to do. I have a site that focuses on the local rock community in my area and want to add a bands archive feature where users can be able look up new bands as we introduce them. Two content types were created for this, one called Band and the other called Albums, both linked together by node reference. The views are displayed using a main view (band) and albums view (as views attached) It gives me what I want but I can't arrange the fields the way I want. What I need is to have the teaser of the band on the left and the background info (such as origin, labels, acts etc) on the right with the body of the node at the bottom of both the teaser and the info. I've been trying for the past week with no avail and help elsewhere proved futile. I would have resort to using a module but there is none for this feature. Can you please advise what I should do. Thanks in advance. Please the link to a page so you can have an idea what I'm referring to here.
Wow, when you explained the difference between field and node row styles, it just clicked! Thanks Bob!
Your videos have taken my development to a whole new level. Thanks again.
In one instance I have the Admin Theme (Module) installed, and when I go to the view it will not see the new template. From there I rescan template files it recognizes the file and I hit "Ok" and then save. It works perfect in the preview but as soon as I go to the live site it does not work. I go back to the theme information and it doesn't recognize the theme template anymore. This is my process, I could really use some help. I have a custom theme I have created and installed, works fine. From there I have created the necessary content types and views. Currently I have the Admin theme module installed. I have tried with and without this installed. I have also tried using Garland as the admin theme and my default theme as well. In the example of the grouping of months in a year view. I have the view outputting all my events for the current year. I have done exactly what that they said to do on the walkthrough on this page: http://drupal.org/node/388140 I created the new views template as specified, I put in the code to rewrite the output of the months so it will group by month. This is all being placed inside the custom theme I created, not the admin theme. However someone suggested that you have to do that to get it to show up (that still did not work). From there, I go to my View then to the Year view and then to Theme information. Right away it does not recognize the new custom view template that I created. So I click "rescan template files" and it will bold the new template file I uploaded. I click "Ok" and then Save the view. I check hte preview and it works great. I have tried this process with and without clearing the views cache. Both times when I go to the page to view it, it does not seem to be working. I then go back to the View I just edited and the custom view template is no longer bold. The other instance I have is the same issue where I have a custom theme, and a custom view template that I get the exact same result. With this one I am purely just trying to customize the field output, nothing fancy. Thanks for the help I hope this makes more sense.
This video made this process very clear for me! thank you very much