开发者

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

I have a node with the following content (inp开发者_JS百科ut mode: php code):

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

If I output node->body, the output is

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)


You should enable (shipped with core) "php.module", which comes with an input-formatter, PHP-filter. That filter allows you to insert php as you mention in nodes. And will eval() that for you on output.


It sounds like you don't use the php filter that's needed to do something like this. The result is your code is escaped.

On a random drupal install I just tested:

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

Outputs

This is a test

When I view the node.


In Drupal, to display html output of a node which have 'PHP Filter' you can do this

echo php_eval(node->body);


You could output

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜