我需要节点标题才能显示一些文本格式。
据我了解,Drupal 的标题字段只是纯文本,它不允许 HTML或任何其他输入格式。真的吗?有没有办法覆盖这个,或者其他解决方案?
我正在使用 Drupal 6。
最佳答案
你可以很容易地在你的主题中做到这一点,有不同的方法来做。最简单的方法可能是在你的 template.php 中完成
/* this function generates the variables that are available in your node.tpl,
* you should already have this in your template.php, but if not create it
*/
function mytheme_preprocess_node(&$vars) {
// It's important to run some kind of filter on the title so users can't
// use fx script tags to inject js or do nasty things.
$vars['title'] = filter_xss($vars['node']->title);
}
函数中发生的事情是它覆盖了 node.tpl 中 $title 的默认值,其中包含用于标题的变量。它通常放置在 h1 或 h2 标签内,因此您应该注意这一点。 filter_xss 用来只允许基本的html标签,所以保护网站,你可以看看那个功能here .那是一些其他过滤器函数,例如 check_markup 和 filter_xss_admin,但是您可以为 filter_xss 提供第二个参数,它是一个允许标签的数组,因此如果默认值不够好,您可以更改它以满足您的需要。
关于drupal - Drupal 节点标题中的 HTML\富文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1535878/