tags:

views:

29

answers:

3

I have a node with the following content (input 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)

A: 

You could output

eval($node->body); // be sure what you are evaling
Elzo Valugi
Drupal should already 'eval' it, really no need toeval it yourself, in fact, chances are this will both horribly break and thta this opens up severe security holes.
berkes
I don't know if Drupal evals a html string before outputting, I would not see why. My response is the PHP solution of what Niyaz wanted.
Elzo Valugi
A: 

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.

berkes
A: 

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.

googletorp