0

The site on which I'm working has a variety of views for multiple sections of the website. These different sections, which are defined by Taxonomy terms, use different themes. So, for example, sections 'X' and 'Y' each have views which we want to be displayed in themes 'X' and 'Y.'

Is there a way in Views to assign the page created by Views a taxonomy term, so that, using ThemeKey, it can be assigned a theme by it's taxonomy term, like the other nodes with that taxonomy term?

I'd really like to do this without using templates, so that it can be easily managed within Drupal's UI.

4
  • So all views will have the same tax term/theme?
    – sareed
    Commented Jul 10, 2015 at 17:35
  • After re-reading I think I would suggest not using page Views and use blocks instead. This way you can assign the tax term to the page and all pages will be under the content menu.
    – sareed
    Commented Jul 10, 2015 at 17:40
  • Different views would have different taxonomy terms and therefore, different themes. But the problem is I don't know how to assign a view a taxonomy term, or if that is even possible.
    – Travis
    Commented Jul 10, 2015 at 18:07
  • Honestly I think you should consider using block displays instead of page displays. You can then use Contextual filters if necessary to use the tax term as an argument in your view once you set it for the node.
    – sareed
    Commented Jul 10, 2015 at 21:25

2 Answers 2

0

In your comment you said : Currently, it is configured to use the URL of a page to determine the theme that page will take so by this assumption:

Use hook_preprocess_views_view as follow and suggest your theme

function YOURTHEME_OR_MODULE_preprocess_views_view(&$vars) {
$path = current_path();
$view = $vars['view'];
switch ($view->name) {

case 'SOME_VIEW_NAME' :
  if($path == "SOME_PATH1_OR_PATTERN1")
       $vars['theme_suggestion'][] = 'views_view__custom_blocks';

  if($path == "SOME_PATH2_OR_PATTERN2")
       $vars['theme_suggestion'][] = 'views_view__ANOTHER_custom_blocks';
break;

case 'ANOTHER_VIEW_NAME' :
  ;
break;

}
}

If the first condition get satisfied create file views-view--custom-blocks.tpl.php and theme your view.

you can also use hook_preprocess_views_view_fields to set the values of the variables of the view.

0

Are you saying that you are using the not-yet-stable 7.x module Taxonomy Theme? Terms are assigned by Term Reference fields on fieldable entities. Since drupal is open source, there is always more than one way to do something. If you wanted to build a site that can do exactly as you have asked here, then I suppose it is possible to make a new entity that has a term reference and also embeds the view in its custom theme processes to get the fusion you are requesting. You will have to crawl into the Taxonomy Theme module code and see if it is using hook_node_view to do the check/change. If so, it would not fire on a straight view anyway but this custom entity (maintenance nightmare) should trigger it.

An easier method would be the template files that you dont want. Use theme_hook_suggestions where you have different tpl.php files for the different views based on path or whatever else you want. Different templates by path alias. You then just have the different templates use the different theme styles. I would also recommend putting the taxonomy term values as body level css classes so you can have one theme, and it just trigger different stylesheets based on term classes. Option1 | Option2 This would relieve your dependence on the dev-version module.

Option 3. In whatever theme is your default, copy the relative style sheets over from the other themes and just use the view-specific css class for each one, applying it manually. This means that you have duplicated style commands, so it will be a little harder to maintain what is coming from where, but at least you dont have to code any php.

Option 4. Sareed's comment about using block displays and embedding the views on other pages that have the terms. (...I should have thought of that)

2
  • We are using the ThemeKey module to define themes (not Taxonomy Theme). Currently, it is configured to use the URL of a page to determine the theme that page will take. We would like to change this so that ThemeKey, instead, reads the taxonomy term of a page and determines the theme this way. The reason for this is so that the Theme and the URL are both using the Taxonomy term of a page to define the theme and URL so its not a daisy-chained set-up of taxonomy -> URL -> theme. I hope that makes sense.
    – Travis
    Commented Jul 10, 2015 at 18:07
  • That makes sense, but I think it is adding complications. With the URL as the theme key, you now have the taxonomy portion of the process as optional. For the views, you can specifically put in the path the term you want without it being a term, and thus evoke the right theme. The configuration that you currently have is the more orthogonal choice. Commented Jul 10, 2015 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.