How to Get PHP Working Inside Template
November 30, 2006 7:15 PM   Subscribe

Help me figure out how to add PHP into a template.

I've purchased a php script and in the admin interface their is template area that you can change how the page looks (See Picture) using html and predefine codes.

When I insert PHP script into the template area, it shows up as plain text on the site. I've emailed the developer but haven't heard any response. Anybody know how I can make PHP actually execute?

Thanks!
posted by bleucube to Computers & Internet (7 answers total)
 
That looks like some kind of custom templating system, where the script will replace %title% with the title, for example. The instructions above the field don't mention using PHP in the template area.

I expect the script treats the text from the template area as plain text, and does a search-and-replace to replace "%title%" with whatever the title is.

Since it's being treated as a plain text string, any PHP you put in there won't be executed. Without fully understanding the script and being able to modify it, it looks like you're out of luck. The developer evidently didn't intend for people to put PHP in the template.

This is not a bad idea on the developers, since the whole point of these kind of templating systems is to insulate you from the raw PHP. Allowing PHP to be executed would probably necessitate use of the eval() function which any sensible developer wants to avoid at all costs, since it can cause security nightmares.

What are you trying to do that requires PHP? Whatever it is, you're probably better off doing it in another part of the script than the templating system.
posted by matthewr at 7:32 PM on November 30, 2006


Unless it specifically says you can do it, I would assume you can't.

That script uses PHP to create pages. You want to add PHP inside the PHP, which could potentially cause all kinds of problems. I would suggest that the only thing you're allowed to use is plain HTML and those variables defined for you.

But tell us what system it is and we can look into it in more detail.
posted by AmbroseChapel at 7:32 PM on November 30, 2006


not a bad idea on the developers [part]
posted by matthewr at 7:32 PM on November 30, 2006


Response by poster: The script is Babeloggerv3, I'm using it for a link dump site. Would it be possible to just add the PHP script to the config page were the rest of the definitions are, so that way I could add something lik %TOP10% and it would run that script?

Thanks for the answers so far!
posted by bleucube at 6:15 AM on December 1, 2006


A templating system like that is designed so that people should not be allowed to arbitarily insert their own PHP code. The security risks are too great.

I imagine you would be able to achieve what you want by creating your own custom %foo% that does what you want by working backwards in the source of the 'predefined codes'.
posted by ReiToei at 6:15 AM on December 1, 2006


The problem you're running up against is that PHP works by parsing the script once. To get the code you're putting in the template to run, PHP would have to parse the script a second time. And that isn't going to happen. It's a chicken and egg problem. Your chicken is laying an egg, and then you want the egg to lay another egg. Which, of course, would be an abomination against God, which PHP doesn't allow for.

The developer would have to make some non-trivial modifications to the application to make it handle PHP or plain text. But of course I've never seen the code, so I'm just guessing.
posted by Bael'Gar at 6:24 AM on December 1, 2006


So besides your other problems, where's your opening and closing tags for the php script?
posted by IronLizard at 6:59 AM on December 1, 2006


« Older Where can I find internet search behavior...   |   Should I retake the LSAT? Newer »
This thread is closed to new comments.