随笔 · 2013/03/19 0

drupal 7 URL指定页面

一个网站的大多数页面都大相径庭的时候,比如:about页面、cases页面、contact页面都不相同的时候可以为每页面指定一个模版页面。

如果访问的页面是http://www.example.com/about,需要为这一内容指定模版页面

Template.php 添加如下内容(THEME为主题名)

 

function THEME_preprocess_page(&$vars) {
  if (module_exists(’path’)) {
        $alias = drupal_get_path_alias(str_replace(’/edit’,’’,$_GET[’q’]));
        if ($alias != $_GET[’q’]) {
            $suggestions = array();
            $template_filename = ’page’;
            foreach (explode(’/’, $alias) as $path_part) {
                $template_filename = $template_filename . ’__’ . $path_part;
                $suggestions[] = $template_filename;
            }
            $vars[’theme_hook_suggestions’][] =  $suggestions[0];
        }
    }
}

阅读更多地内容或参见:http://drupal.org/node/1089656

0
希望看到您的想法,请您发表评论x