简体   繁体   English

如何获取具有php代码的drupal节点的HTML输出?

[英]How to get the HTML output of a drupal node having php code?

I have a node with the following content (input mode: php code): 我有一个具有以下内容的节点(输入模式:php代码):

this is a <?php echo "test" ?>

If I output node->body, the output is 如果我输出node-> body,则输出为

this is a <?php echo "test" ?>

What I want is: 我想要的是:

this is a test

What is the easiest way to do this? 最简单的方法是什么?

(I don't want all the default divs and other structural stuff coming with it when I call node_view) (我不希望在调用node_view时附带所有默认的div和其他结构化的东西)

在Drupal中,要显示具有“ PHP筛选器”的节点的html输出,可以执行此操作

echo php_eval(node->body);

You should enable (shipped with core) "php.module", which comes with an input-formatter, PHP-filter. 您应该启用(随核心提供)“ php.module”,它带有输入格式器PHP过滤器。 That filter allows you to insert php as you mention in nodes. 该过滤器允许您插入节点中提到的php。 And will eval() that for you on output. 并将eval()输出给您。

It sounds like you don't use the php filter that's needed to do something like this. 听起来您没有使用执行此类操作所需的php过滤器。 The result is your code is escaped. 结果是您的代码被转义。

On a random drupal install I just tested: 在随机的drupal安装中,我刚刚进行了测试:

This is a <?php echo 'test'; ?>

Outputs 产出

This is a test

When I view the node. 当我查看节点时。

你可以输出

eval($node->body); // be sure what you are evaling

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM