Drupal6:在theme_preprocess_page(&$vars)中,$vars从哪里来? (如何操作面包屑)
当面包屑只有一个条目(“主页”)时,我想删除它。我在主题的 theme_preprocess_page(&$vars)
函数中。 $vars['breadcrumb'] 可用,但它只是 HTML。这使用起来有点笨拙。我宁愿将其作为面包屑列表中的项目数组获取,并执行以下操作:
if (count($breadcrumb) == 1) {
unset($breadcrumb);
}
$vars
来自哪里?如何覆盖最初创建它的代码?
I want to remove the breadcrumb when it's just one entry ("Home"). I'm in my theme's theme_preprocess_page(&$vars)
function. $vars['breadcrumb'] is available, but it's just HTML. This is a bit to clumsy to work with. I'd rather get it as an array of items in the breadcrumb list, and do something like this:
if (count($breadcrumb) == 1) {
unset($breadcrumb);
}
Where does $vars
come from? How can I override the code creating it originally?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$vars 数组在所有预处理函数之间传递。对于 _preprocess_page 函数,$vars 中的大部分值都是在 template_preprocess_page 中创建的(请参阅 http://api.drupal.org/api/function/template_preprocess_page/6)。在该函数中,您将看到:
这里,drupal_get_breacrumb 返回一个面包屑元素数组,然后由 theme_breadcrumb() 函数(或其覆盖)设置主题。
获得所需内容的最简单方法是覆盖 theme_breadcrumb 函数。为此,您需要使用原始的 theme_breadcrumb 函数 (http://api.drupal.org /api/function/theme_breadcrumb/6),将其复制到您的 template.php,将函数名称中的“主题”替换为您的主题名称并更改代码,使其如下所示:
为了更好地理解有关 Drupal 主题覆盖和预处理功能的信息,请参阅 关于覆盖主题输出 和 设置在模板中使用的变量(预处理函数)。
A $vars array is passed on between all preprocess functions. In case of the _preprocess_page functions, most of the values in $vars are created in template_preprocess_page (see http://api.drupal.org/api/function/template_preprocess_page/6). In that function, you'll see:
Here, drupal_get_breacrumb returns an array of breadcrumb elements, which is then themed by the theme_breadcrumb() function (or its override).
The easiest way to get what you want is to override the theme_breadcrumb function. To do that, you take the original theme_breadcrumb function (http://api.drupal.org/api/function/theme_breadcrumb/6), copy it to your template.php, replace 'theme' in the function name with the name of your theme and alter the code so it looks like this:
For a better understanding of Drupal theme overrides and preprocess functions, see About overriding themable output and Setting up variables for use in a template (preprocess functions).