1

I'm working on creating different themes in different pages of a site base on several conditions.

first, I want to create a page.tpl.php for all view pages in my site.

second, I want to have tiny specialization on it base on the filter criteria field's value or selected field's value in a page view. I mean different page.tpl.php based on fields value criteria.

I need to change the overall theme so it is not duplicate of is it possible to have one views-view--VIEWNAME--page.tpl for multiple views?

I need to know how to access field's value in my "function MYTHEME_preprocess_page(&$vars, $hook) ".

0

Salam, You can do this using hook_preprocess_views_view(&$vars). Your code should be like this:

function YOURTHEME_OR_MODULE_preprocess_views_view(&$vars) {
    $view = $vars['view'];
    // the values of the view, filter criteria and the value of fields are in $view
    if(CONDITION1 == true)   
        $vars['theme_suggestion'] = 'views_view__custom_pages1'
    else if(CONDITION2 == true)   
        $vars['theme_suggestion'] = 'views_view__custom_pages2'
}

Then create files views_view__custom_pages1.tpl.php and views_view__custom_pages2.tpl.php and theme the view. In this way different themes are defined for the same view.

You also said I need to know how to access field's value in my "function MYTHEME_preprocess_page(&$vars, $hook) ", what variables do you need to find it's value?

  • salam! :) does it override page.tpl.php or just the the area of the view? About fields' value I need to have different overridden page.tpl.php depend on the taxonomy ID in my Contextual filter. – shekoufeh Jun 10 '15 at 6:23
  • it effects the view's context. If you need to change the entire page.tpl.php use the above code in hook_preprocess_page and check for the value of the view. The above function is called before the hook_preprocess_page so you can set a static variable which it's value is the value of the view then use that variable in the hook_preprocess_page. – M a m a D Jun 10 '15 at 8:12
  • I try it but doesn't work. I do this in another way for now. thanks a lot anyway. – shekoufeh Jun 14 '15 at 8:16
  • You can also use context module – M a m a D Jun 24 '15 at 14:25
  • that's right but I don't like module base approaches. thanks – shekoufeh Jun 25 '15 at 4:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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