Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-04-06 04:42:17

Gimpy
New Member
Registered: 2009-04-06
Posts: 9

Add php within an article

I want to write some php code within my article.

1. I’m using Textpattern · 4.0.8
2. “Allow PHP in pages”, “Allow PHP in articles” and “Allow raw php”, are all set to yes.

PHP code must be both without opening and closing PHP tags, and enclosed within txp:php tags.”

3. I’ve written it this way :

<txp:php> echo “1”;
</txp:php>

How can I make this work ?

Thanks!

Offline

#2 2009-04-06 04:50:04

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Add php within an article

Not sure what you are asking.

<txp:php>  echo “1”;
</txp:php>

does work.

Offline

#3 2009-04-06 04:52:05

Gimpy
New Member
Registered: 2009-04-06
Posts: 9

Re: Add php within an article

Well i’ve got an error saying :

Parse error: syntax error, unexpected ‘<’ in /home/…/textpattern/publish/taghandlers.php(3089) : eval()’d code on line 1

Last edited by Gimpy (2009-04-06 04:52:32)

Offline

#4 2009-04-06 04:59:21

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Add php within an article

Hmm, copied and pasted what you have actually posted here and it returns “1” in my article form nicely, that is with the quotes if that is what you intend – might try copying the code here back to your article form.

Offline

#5 2009-04-06 05:02:10

Gimpy
New Member
Registered: 2009-04-06
Posts: 9

Re: Add php within an article

Yup, done that, but with no success. It’s weird.

Offline

#6 2009-04-06 05:03:59

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Add php within an article

Does the error persist if you remove the code in question altogether?

Offline

#7 2009-04-06 05:06:29

Gimpy
New Member
Registered: 2009-04-06
Posts: 9

Re: Add php within an article

if I remove “</txp:php>”, the error disapear, but nothing it displayed.

In the source code, i’ve got a lonely <p> where “<txp:php> echo “1”;” should be.

Offline

#8 2009-04-06 05:09:51

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Add php within an article

Could you post your code in a little larger context, say the entire article form if that is where you are using it.

Offline

#9 2009-04-06 05:17:06

Gimpy
New Member
Registered: 2009-04-06
Posts: 9

Re: Add php within an article

Well my article is completely blank. It only has a title which is “test”.

In the body, i’ve written the code I wrote in my first post.

When looking at the article when published, i’ve got this error message : Parse error: syntax error, unexpected ‘<’ in /home/…/textpattern/publish/taghandlers.php(3089) : eval()’d code on line 1

I don’t know what to write as a larger context. That’s pretty much all there is to say.

Offline

#10 2009-04-06 05:24:29

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Add php within an article

If you use an unclosed tag this way: “<txp:php> echo “1”;” TXP will look for the closing tag and the response is a blank. The lonely paragraph tag is probably a textile response. What you have posted here should work in an article form, and it does anywhere I use it. I can’t reproduce what you are seeing, so we are missing something obvious I would suspect.

Given that you have settings for raw php set to yes, try <?php echo “1”; ?> , if that works – set it to no and try the TXP tags.

Last edited by rsilletti (2009-04-06 05:31:59)

Offline

#11 2009-04-06 05:30:33

Gimpy
New Member
Registered: 2009-04-06
Posts: 9

Re: Add php within an article

It should work indeed. There’s nothing simplistic then that.

I’ve checked again, and the advance settings regarding php in an article or a page in the admin are all set to yes. It’s also a completely new install and didn’t get any error message while installing it.

I just can’t see where the error could be. It’s like if it didn’t like the closing tag, but I don’t see why.

Offline

#12 2009-04-06 05:33:36

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Add php within an article

Given that you have settings for raw php set to yes, try <?php echo “1”; ?> , if that works – set it to no and try the TXP tags.

Offline

#13 2009-04-06 05:39:11

Gimpy
New Member
Registered: 2009-04-06
Posts: 9

Re: Add php within an article

Ok, here’s the result

The php written in a page (the skeleton with all the html) works perfectly. (Allow php in pages is set to yes.)

The php within an article gives me the error were trying to solve.

If I do not allow php in an article, the error disapear.

If I do not allow php in an article, but allow raw php, I get a similer error, but worse. The page goes completely white with the line :
Parse error: syntax error, unexpected ‘>’ in /home/…/textpattern/publish.php(1137) : eval()’d code on line 35

(The other error didn’t affect the website design, i was only displying the error when the “1” should have been.)

Last edited by Gimpy (2009-04-06 05:40:14)

Offline

#14 2009-04-06 05:47:00

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Add php within an article

Allow php in articles set to yes
Allow raw php set to no

Article form content.

<txp:php> echo “1”; </txp:php> is the correct code for that configuration.

How this may behave without some surrounding content isn’t something I’ve tested.

Offline

#15 2009-04-06 05:50:26

Gimpy
New Member
Registered: 2009-04-06
Posts: 9

Re: Add php within an article

That’s exactly what I’ve got now, and it still give me the error message.

It should work fine without any surrounding content.

Thanks for your help anyways.

I’m going to sleep, since it’s 1h50am here :P I’ll be back tomorrow.

Offline

Board footer

Powered by FluxBB