开发者

How to show different Views on different Drupal Themes

Say I have a default theme for my drupal site. Here I h开发者_StackOverflow中文版ave created views, blocks, etc and styled everything the way I want for the public. Now, as the admin I would like to have an entirely separate theme. No problem, I create a second theme in the themes directory and switch my admin user theme configuration to the second theme. But, what if in my second theme I want to show entirely different content (i.e. Views, blocks, etc). Let's use my front page as an example (front). Right now my front page has a slideshow using Views. This view obviously shows up on the front page no matter what theme I'm using. So for my front page, how could I show an entirely different View (say a list of blog posts) for the second theme than the slideshow View I'm using for the first theme?


The easiest way is to put your views in a block, as blocks are configured per theme. Different themes can have completely different block configurations. A potential issue with this approach is that it does take some more work to get things like arguments to play nicely with views that are hosted in blocks.

Another option which may work for you is to just have the same view themed different ways. Views plays very nicely with the theme layer of Drupal and you can create template files for a particular view or view display. Check out the theme info link in the views admin page to see all the possible overrides for a view. Of course this is assuming that there are some common elements between what you want to show.

A third option might be to display multiple views on the one page, and use the permissions system to ensure only one is shown at any one time. I have used this approach in the past but it did get somewhat unwieldy to manage because as requirements changed I had to replicate the changes across multiple views.


If the question is about the admin theme that fires on different paths and blocks have path visibility settings. Views do not just appear on a page, if they are in a block, that's handled if not -- how do they appear on the page?

As for front, if you say have two themes and user can switch then you need your own "routing code". There is no support for this. Ie you need your own blocks that call out to the relevant blocks depending on the theme.


This seams like a wonder application of two fairly new but very powerful modules.

Context - http://drupal.org/project/context in conjunction with Spaces - http://drupal.org/project/spaces

or

Panels http://drupal.org/project/panels

Both have concepts that allow you to set a context for pages that changes the output based on a variety of criteria. In your case the criteria would be the role of the user viewing the page. Both more less unwieldy than the tricks that CurtainDog offered up, which btw are all very valid approaches. The advantage of these two modules is that they make the organization and selection process much more sane and simple.

It's difficult to advise one over the other, but in a nutshell: Panels has more options in the interface, but has a bit of a learning curve on the code level. Context / Spaces is very easy to work with on the programing level, but required more coding to accomplish most tasks. I would suggest trying both before committing to either. For a wonderful discussion of both listen to this podcast.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜