Skip to main content
added 165 characters in body
Source Link
M a m a D
  • 3.8k
  • 2
  • 32
  • 62

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, 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.

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?

Source Link
M a m a D
  • 3.8k
  • 2
  • 32
  • 62

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.