无法覆盖融合子主题中的 theme_links()
我在 Fusion 下设置了一个子主题,并在我的子主题中创建了一个 template.php 文件。我添加了以下主题覆盖,并且效果完美。
function ThemeName_menu_local_tasks() {
$output = '';
if ($primary = menu_primary_local_tasks()) {
$output .= "<div class=\"tabs primary\">\n";
$output .= "<ul class=\"tabs primary\">\n" . $primary . "</ul>\n";
$output .= "</div>\n";
}
if ($secondary = menu_secondary_local_tasks()) {
$output .= "<div class=\"tabs secondary\">\n";
$output .= "<ul class=\"tabs secondary\">\n" . $secondary . "</ul>\n";
$output .= "</div>\n";
}
return $output;
}
function ThemeName_filter_tips_more_info () {
return '';
}
function ThemeName_filter_tips() {
return '';
}
但是,当我尝试覆盖 theme_links 时,它根本不起作用。
function ThemeName_links($links, $attributes = array('class' => 'links')) {
global $language;
$output = '';
if (count($links) > 0) {
$output = '<div class = "abc"><ul' . drupal_attributes($attributes) . '>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$class = $key;
// Add first, last and active classes to the list of links to help out themers.
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
&& (empty($link['language']) || $link['language']->language == $language->language)) {
$class .= ' active';
}
$output .= '<li' . drupal_attributes(array('class' => $class)) . '>';
if (isset($link['href'])) {
// Pass in $link as $options, they share the same keys.
$output .= l($link['title'], $link['href'], $link);
}
else if (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in <span> for adding title and class attributes
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= '<span' . $span_attributes . '>' . $link['title'] . '</span>';
}
$i++;
$output .= "</li>\n";
}
$output .= '</ul></div>';
}
return $output;
}
顺便说一下,我在上面的 ThemeName_links() 中添加了以下内容进行测试。
<div class = "abc"> and </div>
我还使用 Devel 清除了刷新所有缓存。
I have setup a subtheme under Fusion and created a template.php file in my subtheme. I have added the following theme overrides and it works perfectly.
function ThemeName_menu_local_tasks() {
$output = '';
if ($primary = menu_primary_local_tasks()) {
$output .= "<div class=\"tabs primary\">\n";
$output .= "<ul class=\"tabs primary\">\n" . $primary . "</ul>\n";
$output .= "</div>\n";
}
if ($secondary = menu_secondary_local_tasks()) {
$output .= "<div class=\"tabs secondary\">\n";
$output .= "<ul class=\"tabs secondary\">\n" . $secondary . "</ul>\n";
$output .= "</div>\n";
}
return $output;
}
function ThemeName_filter_tips_more_info () {
return '';
}
function ThemeName_filter_tips() {
return '';
}
However, when I try to override theme_links, it doesn't work at all.
function ThemeName_links($links, $attributes = array('class' => 'links')) {
global $language;
$output = '';
if (count($links) > 0) {
$output = '<div class = "abc"><ul' . drupal_attributes($attributes) . '>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$class = $key;
// Add first, last and active classes to the list of links to help out themers.
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
&& (empty($link['language']) || $link['language']->language == $language->language)) {
$class .= ' active';
}
$output .= '<li' . drupal_attributes(array('class' => $class)) . '>';
if (isset($link['href'])) {
// Pass in $link as $options, they share the same keys.
$output .= l($link['title'], $link['href'], $link);
}
else if (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in <span> for adding title and class attributes
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= '<span' . $span_attributes . '>' . $link['title'] . '</span>';
}
$i++;
$output .= "</li>\n";
}
$output .= '</ul></div>';
}
return $output;
}
By the way, I added the following to ThemeName_links() above for testing.
<div class = "abc"> and </div>
I have also cleared Flush all cache using Devel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你所做的一切都是正确的(我指的是你进行主题覆盖的方式)并且 Fusion 主题系统也运行良好。起初,当我尝试使用 Fusion 主题时,我遇到了与您相同的问题。但是当我浏览完 Fusion 系统并查看 Fusion 如何显示链接(包括主链接、辅助链接)后,我发现在 fusion/fusion_core/page.tpl.php 文件中他们调用此函数 theme('grid_block', $primary_links_tree, 'primary-menu') 显示主链接。这是Fusion写的功能主题。所以你需要做的很简单,你可以调用Drupal的默认主题链接函数:theme('links', $primary_links)并从那里覆盖你的ThemName_links()。
我现在想做的另一件事是覆盖 grid_block 函数。如果我发现一些有趣的事情,我稍后会发布更多内容。
Everything you do is correct (I am referring to the way you do theme override) and Fusion theme system also works well. At first, when I try to use Fusion theme, I face the same issue as you. But after I went through the Fusion system, and see how Fusion shows the links (include primary-links, secondary-links), I discovered that inside fusion/fusion_core/page.tpl.php file they call this function theme('grid_block', $primary_links_tree, 'primary-menu') to show the primary-links. This is the function theme written by Fusion. So what you need to do is simple, You can call the default theme links function of Drupal: theme('links', $primary_links) and override your ThemName_links() from there on.
One more thing I'm trying to do now is to override grid_block function. If I find out something interesting, I will post more later.