Drupal: Print field without markup(Drupal:打印没有标记的字段)
问题描述
有没有办法在不获取所有标记的情况下打印字段内容?我是 Drupal 的新手,但我知道 field.tpl.php,但是,我只是想知道是否有一种更快的方法来获取节点中的内容——custom.tpl.php.它将与 Wordpress 的 <?php echo get_field('field_name'); 进行比较.?>
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'); ?>
推荐答案
嗯,除了用field.tpl.php,我还能想到2个解决方案:
Well, apart from using field.tpl.php, I can think of 2 solutions:
第一:
使用 php 代码段去除 template.php 中的 html 标签.
Use a php snippet to strip html tags in your template.php.
在你的 template.php 中
in your template.php
function mytheme_strip_html_tags($n_field) {
return preg_replace("/<.*?>/", "", $n_field);
}
然后调用函数mytheme_strip_html_tags($field_name)
但是,如果您使用多个主题,则需要将此代码段复制到每个主题中.
if you use several themes, however, you need to copy this snippet to each one of them.
您可以制作一个模块并将该片段放入其中.这样,它适用于每个主题.
You can make a module and place that snippet inside. This way it works with every theme.
第二个:
下载令牌模块.令牌是对您的字段的引用.Tokens 模块有一个输出模式,可以为你去除 html.[field_name-raw]
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:打印没有标记的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Drupal:打印没有标记的字段


- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01