Theming views page displays

Events happening in the community are now at Drupal community events on www.drupal.org.
bjc5070's picture

I am trying to theme my views page displays, but its not working.

What I have...
OG groups each with there own theme.
views outputting page displays per taxonomy term.
each OG group has its own view and set of page displays per term.

I need...

each view to display its page displays in the corresponding theme.

I have tried...

Basic settings > style:unformatted > configure. ( doesnt seem to do anything)
Basic setings > Theme:infomation (also no good)

my views are creating teaser lists of articles by taxonomy terms. I am using fusion and acquia prosper. any ideas? I hope this makes sense.

Comments

Not sure I follow exactly

gregoryshearer's picture

So just to be clear a "page" type Display in a View just means that the view will be in the form of a web page, it the sense that it can be placed on a menu and people can navigate to it. This is opposed to say a block output, which would display in a block region on several pages. Point being that outputting a list of teasers is a very common application of views.

"Basic Settings > style: unformatted" indicates that whatever fields you select under "Fields" will be output very simply, with each field just wrapped in a div, and each set of output fields wrapped in a div. You can set it to HTML list and each set will be wrapped in an

  • instead.
  • The number of items being output per page is also set under Basic information. A common thing I do is set up a content type like "Press Releases" then output page view that is a list of the titles, linked to the actual node, sorted with the newest first. Then when the client adds a new press release it automatically goes onto the list.

    Theme Information gets sort of advanced. It tells you what file names views will recognize as potential template files to control specific output. You can then create such a template file and drop it in with your theme files and Views should pick it up.

    In almost every case to really get the View to look how you want you need to extend the CSS for your theme to accommodate the View output. When you are creating a View you are creating a new type of output that the theme designers could not have anticipated needing styles for. I usually add a line to the theme's .info file to define a new css file and then create that file and put all my new css and overrides in there so that when you update the theme your changes are neatly separated.

    I am probably answering the wrong question again so I will leave it at that.. good luck! :)

    Good clear overview of views basics

    fen's picture

    Thanks, @gregoryshearer. Views is at once simply beautiful and powerfully deep. I'm still a neophyte at creating and managing views, and as a non-themer the theming side of things is simply beyond me. (Fortunately, standard views lists and tables normally do the trick for my simple needs.)

    But there is some magic in between hooking up views to templates, and indeed it may not be so "magic" if I understood theming better to begin with. Can you recommend and simple "introduction to theming for the non-themer" resources?

    Thanks!

    greg, that definately helps

    bjc5070's picture

    greg,

    that definately helps me. Im not sure what i am going to do yet. maybe try styleing in html.

    Views Templates

    marktfrey's picture

    @gregoryshearer: nice overview! One thing i would recommend against is adding additional code to downloaded themes that you might need to update. It's usually better to create a subtheme instead, and modify or add to the css as needed there. Zen has an excellent guide on how to do this, but you can subtheme pretty much any theme -- that way you won't have to remember to update the .info file everytime you update.

    @bjc5070: if you're trying to alter the actual html output of the view, rather than just tuning the styles of what views outputs by default, you'll need to explore views theming.

    Template suggestions are actually built into views, it the theme: Information link under each display (separate for each page/block/feed/attachement within your view). Under that link, you'll find a list from least-specific to most-specific of all the .tpl.php suggestions views looks for. The one views is currently using is in bold. If you click the template that you want, the default template code comes up, and you can copy that and paste it into a new file, change the name to whatever-template-name-youve-decided.tpl.php, and save it to your theme's directory.

    The tricky part is that most of the views templates just say print $output;, but you have access to other variables including the view itself and $field. You can dpm these (if you have devel enabled) or print_r to see what info is where.

    Here are some basic links from a quick google:
    This has an explanation of what the template files do: http://drupal.org/node/352970
    This goes into more detail: http://www.group42.ca/theming_views_2_the_basics
    Mustardseed podcasts are usually pretty (very) good. http://mustardseedmedia.com/podcast/episode23
    didn't watch the whole thing, but it's pretty good (at the beginning at least) and should get you the basics.

    That is a pretty good treatment

    gregoryshearer's picture

    Thanks marktfrey, that is a better run-down of the View template options. One important point is that the views templates can be applied at the Field level. For example, if you want a particular field to always output as a heading 1 you can make a template file for JUST that one field that wraps the "print output;" line in H1 ... /H1 tags.

    The node/page level templates get much more complicated, and you need to be able to work with the PHP variables directly, as you mention.

    However, IMO this is really just one approach to "Theming" in general. I personally find it easier to just use FireBug to look at what Views spits out without any templates and just write styles to position, float, and size things so it looks right. I am not saying that approach is better, just what I know. I am not sure which would be easier to pick up as a new learner though.. learning to style CMS output with CSS or learning to write PHP/HTML templates from scratch!

    One "quick and dirty" thing to look at in Views is the option to "Rewrite the output of this field" listed under the field output settings. Like the above example, say you are outputing the node Title. You can rewrite the output of that field and wrap the [Title] token in H1 tags. This way the H1 tags are included as part of the actual Views output before any templates are applied.

    thanks

    cartagena's picture

    I'm grateful for the views discussion...gotten much better at it and this helps. My styling method is more CSS... and views and panels makes that easy. I'm just wondering, though, is there ever too much CSS? I mean, at some point will it slow the page down? I used CSS to style a photo slider and when I checked "aggregate CSS" to speed things up it totally messed up the slider. Just wondering if I need to be more careful.

    Pittsburgh

    Group notifications

    This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: