Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 Yesterday 20:12:15

amordecosmos
Plugin Author
From: London (Hometown: Vancouver)
Registered: 2004-08-03
Posts: 118
Website

<txp:php> and javascript

Usually you can place some php in javascript, such as to echo a variable, without much hassle.

But <txp:php> always causes a syntax error for me.

Can it be done? Am I doing it wrong?

Update: solved

For anyone reading this in the future.

Putting global before the $variable in the javascript is what fixed it.

Last edited by amordecosmos (Today 01:24:08)

Offline

#2 Today 11:12:24

etc
Developer
Registered: 2010-11-11
Posts: 5,452
Website GitHub

Re: <txp:php> and javascript

amordecosmos wrote #340456:

Putting global before the $variable in the javascript is what fixed it.

Glad it’s solved, but, to make things more future-proof, you can (in 4.9?) inject values this way:

<txp:php my_var='<txp:variable name="my_var" />'>
    echo $my_var; //or whatever
</txp:php>

Offline

Board footer

Powered by FluxBB