Drupal 7 Template Suggestions

来源:互联网 发布:bose musicmonitor知乎 编辑:程序博客网 时间:2024/04/30 10:46


<?php

//template.php
// Add a single suggestion for nodes that have the "Promoted to front page" box checked.
function drop_preprocess_node(&$variables) {
  if (
$variables['promote']) {
   
// looks for node--promoted.tpl.php in your theme directory
   
$variables['theme_hook_suggestion'] = 'node__promoted';
  }
}

// Add multiple suggestions for pages based on the logged in user's roles.
function drop_preprocess_page(&$variables) {
  global
$user;
 
  if (!empty(
$user->roles)) {
    foreach (
$user->roles as $role) {
     
$filter = '![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s';
     
$string_clean = preg_replace($filter, '-', drupal_strtolower($role));

     
// looks for page--[role].tpl.php in your theme directory
      // ex: page--administrator.tpl.php
     
$variables['theme_hook_suggestions'][] =  'page__'. $string_clean;
    }
  }
}
?>