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) ".

1

1 Answer 1

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?

5
  • 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
    Commented Jun 10, 2015 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
    Commented Jun 10, 2015 at 8:12
  • I try it but doesn't work. I do this in another way for now. thanks a lot anyway.
    – shekoufeh
    Commented Jun 14, 2015 at 8:16
  • You can also use context module
    – M a m a D
    Commented Jun 24, 2015 at 14:25
  • that's right but I don't like module base approaches. thanks
    – shekoufeh
    Commented Jun 25, 2015 at 4:03

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.