【发布时间】:2015-04-02 17:18:06
【问题描述】:
我遇到了一些处理这个问题的线程,但它们都非常具体,因此令人困惑。
一般来说,组合多个功能的最佳做法是什么?我在 Drupal 安装的 template.php 文件中使用它来进行主题化。
假设我有两个功能:
function mytheme_preprocess_page(&$variables){
(...)
}
和
function mytheme_preprocess_page(&$vars, $hook){
(...)
}
当我在我的 template.php 中使用这两个函数时,我收到了 致命错误:无法重新声明 mytheme_preprocess_page()(之前在(文件)中声明。
这是完整的代码:
function mytheme_preprocess_page(&$variables){
// Add information about the number of sidebars.
if (!empty($variables['page']['sidebar_first']) && !empty($variables['page']['sidebar_second'])) {
$variables['content_column_class'] = ' class="col-sm-6 main-content"';
} elseif (!empty($variables['page']['sidebar_first']) || !empty($variables['page']['sidebar_second'])) {
$variables['content_column_class'] = ' class="col-sm-9 main-content"';
} else {
$variables['content_column_class'] = ' class="col-sm-12 main-content"';
}
}
function mytheme_preprocess_page(&$vars, $hook){
if (isset($vars['node'])) {
switch ($vars['node']->type) {
case 'article':
$vars['title'] = '';
break;
}
}
}
我知道我应该合并这些函数。问题是:如何?
因为这些(&$variables) 和(&$vars, $hook) 似乎对于每个单独的部分都是必需的。
【问题讨论】:
标签: php function merge drupal-7 drupal-theming