Thursday, 12 April 2012

Drupal7 template.php

Usually all functions for building a theme structure should be written in this file. You should be familiar with the variables and API that are used in this file.
https://api.drupal.org/api/drupal/themes!garland!template.php/7
https://drupal.org/node/1089656

Here's a sample code. There are lots of important APIs and the variables
-------------------------------------------------------------------------------------
function mytheme_preprocess_html(&$variables) {
    if(!empty($variables['page']['featured'])) {
    $variables['classes_array'][] = 'featured';
    }
}
function mytheme_process_html(&$variables) {
    if(module_exists('color')) {
        _color_html_alter($variables);
    }
}
function mytheme_process_page(&$variables) {
    if(module_exists('color')) {
        _color_page_alter($variables);
    }
    $variables['hide_site_name'] = theme_get_setting('toggle_name') ? FALSE:TRUE;
    $variables['hide_site_slogan'] = theme_get_setting('toggle_slogan') ? FALSE:TRUE;

    if ($variables['hide_site_name']) {
        $variables['site_name'] = filter_xs_admin(variable_get('site_name', 'My Theme'));
    }
    if($variables['hide_site_slogan']) {
        $variables['site_slogan'] = filter_xs_admin(variable_get('site_slogan', ''));
    }
 }
------------------------------------------------------------------------------------- 

No comments:

Post a Comment