Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-02-02 19:18:52

wii
Member
Registered: 2005-05-08
Posts: 77

PHP in my templates

How do I add PHP in my templates using textpattern ? I have this for example:

<?php require_once(“/home/wii/public_html/stats/counter.php”);?>

How do I convert the above, so it works in textpattern?

I´ve been looking at this: http://textpattern.com/faq/34/how-do-i-use-php-code

But can´t get it to work.

Thanks

Offline

#2 2007-02-02 20:14:15

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: PHP in my templates

From the FAQ:

Make sure you use <txp:php></txp:php> instead of <?php ... ?> or <? ... ?>.

There is an Advanced Preference that can be used to disable PHP code.

Did you set this right in Admin > Preferences > Advanced? (somewhere under ‘Publish’: Allow PHP in pages?)

Offline

#3 2007-02-10 12:38:00

wii
Member
Registered: 2005-05-08
Posts: 77

Re: PHP in my templates

I did set this right in Admin.

I´m trying for a simple PHP include, like this:

<txp:php>include(“/home/wii/public_html/stats/counter.php”)</txp:php>

But I get an error:

Parse error: parse error, unexpected $ in /home/wii/public_html/beta/textpattern/publish/taghandlers.php(2681) : eval()’d code on line 1

Last edited by wii (2007-02-10 12:38:23)

Offline

#4 2007-02-10 17:56:29

NyteOwl
Member
From: Nova Scotia, Canada
Registered: 2005-09-24
Posts: 539

Re: PHP in my templates

I get the same thing with the include and virtual functions using <txp:php>


Obsolescence is just a lack of imagination. / 36-bits Forever! / #include <disclaimer.h>;

Offline

#5 2007-02-10 18:05:22

wii
Member
Registered: 2005-05-08
Posts: 77

Re: PHP in my templates

Does that mean that PHP includes are not possible within Textpattern ?

Offline

#6 2007-02-10 21:17:21

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: PHP in my templates

Yes, they are most certainly possible. I haven’t had a problem with them at all.

So, if you run stats/counter.php directly, you don’t get any errors/warnings?

Offline

#7 2007-02-10 21:28:28

wii
Member
Registered: 2005-05-08
Posts: 77

Re: PHP in my templates

Directly, yes, the include works on my current page, which is hardcoded.

Can you tell me exactly how your includes look like within textpattern ?

Thanks

Offline

#8 2007-02-13 18:37:36

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: PHP in my templates

I can do either relative or absolute includes:

<txp:php>include('my-file.php');</txp:php>
<txp:php>include('/path/to/my-file.php');</txp:php>

Both work exactly the same for me. I’ve no problems with require, include_once or require_once either.

…the include works on my current page, which is hardcoded.

  • Is there further PHP in that file?
  • Do you have error reporting turned on?

Offline

#9 2007-04-07 14:33:19

wii
Member
Registered: 2005-05-08
Posts: 77

Re: PHP in my templates

This works fine Mary, but why can´t I use this code in the articles themselves ? They only work in the template.

Thanks

Offline

#10 2007-04-07 18:14:40

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: PHP in my templates

It’s likely Textile causing the problem. FAQ

Offline

#11 2007-04-07 19:09:24

wii
Member
Registered: 2005-05-08
Posts: 77

Re: PHP in my templates

Thanks, problem solved.

Offline

Board footer

Powered by FluxBB