问题描述
有没有办法打印字段内容,而没有得到所有的标记?我是Drupal的新手,但我知道field.tpl.php,但是,我只是想知道如果有更快的方法来获取一个节点的内容 - custom.tpl.php。它将与Wordpress的<?php echo get_field('field_name')进行比较; ?>
嗯,除了使用field.tpl.php,我可以想到2解决方案:
first:
使用php代码片段来剥离你的template.php中的html标签。 / p>
in your template.php
function mytheme_strip_html_tags($ n_field){
return preg_replace(/<。*?> /,,$ n_field);
}
然后调用函数 mytheme_strip_html_tags $ field_name)
如果您使用多个主题,则需要将此代码段复制到每个主题。
编辑:您可以制作一个模块并将该片段放在里面。
第二:
下载令牌模块。令牌是对您的字段的引用。令牌模块有一个输出模式,为您剥离html。 [field_name-raw]
您需要遵循如何添加令牌的说明,但并不困难。
Is there a way to print field content without getting all the markup? I'm new to Drupal, but I'm aware of the field.tpl.php, however, I'm just wondering if there's a quicker way to get the content in a node--custom.tpl.php. It would compare to Wordpress's <?php echo get_field('field_name'); ?>
Well, apart from using field.tpl.php, I can think of 2 solutions:
first:
Use a php snippet to strip html tags in your template.php.
in your template.php
function mytheme_strip_html_tags($n_field) {
return preg_replace("/<.*?>/", "", $n_field);
}
then call the function mytheme_strip_html_tags($field_name)
if you use several themes, however, you need to copy this snippet to each one of them.
EDIT: You can make a module and place that snippet inside. This way it works with every theme.
second:
Download the tokens module. Tokens are references to your fields. Tokens module have a output mode that strips html for you. [field_name-raw]
You need to follow instructions in how to add tokens, but is not that difficult.
这篇关于Drupal:打印字段无标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!