if ($node->type == 'x') 在 theme_upload_attachments 函数中不起作用
我希望上传文件的标题根据节点类型显示不同的文本。我重写了核心函数,将其复制到主题的 template.php 文件中,并将其重命名为 phptemplate_upload_attachments。
<?php
function phptemplate_upload_attachments($files) {
global $node;
$header = array(t('Default text'), t('Size'));
if ($node->type == 'orange') {
$header = array(t('ORANGE CUSTOM TEXT'), t('Size'));
}
$rows = array();
foreach($files as $file) {
$file = (object)$file;
if ($file->list && empty($file->remove)) {
$href = file_create_url($file->filepath);
$text = $file->description ? $file->description : $file->filename;
$rows[] = array(l($text, $href), format_size($file->filesize));
}
}
if (count($rows)) {
return theme('table', $header, $rows, array('id' => 'attachments'));
}
}
?>
正如您所猜测的,我只添加了橙色节点类型的行,但它不起作用。我知道该函数已被正确覆盖,因为我测试了它更改了默认文本。另外,我清除了缓存,并尝试添加全局 $node。
为什么这不起作用?
I want the header for the uploaded files to display a different text depending on the node type. I overrided the core function copying it into my theme's template.php file and renamed it to phptemplate_upload_attachments.
<?php
function phptemplate_upload_attachments($files) {
global $node;
$header = array(t('Default text'), t('Size'));
if ($node->type == 'orange') {
$header = array(t('ORANGE CUSTOM TEXT'), t('Size'));
}
$rows = array();
foreach($files as $file) {
$file = (object)$file;
if ($file->list && empty($file->remove)) {
$href = file_create_url($file->filepath);
$text = $file->description ? $file->description : $file->filename;
$rows[] = array(l($text, $href), format_size($file->filesize));
}
}
if (count($rows)) {
return theme('table', $header, $rows, array('id' => 'attachments'));
}
}
?>
As you can guess, I only added the line for the orange node type, but it does not work. I know the function is correctly overidden because I tested it changing the default text. Also, I cleared the cache, and i tried adding global $node.
Why is this not working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$node
可用吗?试试这个:Is
$node
available? Try this: