QUESTION:

My PHP code doesn’t work properly in an article body
My Javascript code doesn’t work properly in an article body



ANSWER:

It is possible to put PHP and Javascript code directly inside an article body (there are some security settings for PHP code).

However, there are some limitations. Textile—the article markup used by Textpattern—doesn’t understand PHP or Javascript syntax, so it can’t always tell where the code starts and ends. This means Textpattern might try to interpret part of your PHP or Javascript code as Textile markup, which will almost certainly prevent it from working.

If you have more than a few lines of PHP or Javascript code, don’t put it directly in an article body. Instead, paste it into a new form of type “Misc”, and use the following tag to call the code:

<txp:output_form form="my_js_code" />

If you often find yourself calling code from article bodies, you might consider rethinking your design. Articles are for content, code is more appropriate for a page template or form. See if you can place the code in your article form instead.