PDA

View Full Version : Making PHP work in templates - hopeless?


spidersilk
01-30-2006, 06:34 AM
I've been trying to customize the templates on my directory to match the rest of my site, and I'm starting to think it's completely hopeless.

First it choked on the Javascript, but I searched through the forums and found the {literal} tag and that seemed to work. Or at least, stopped it from throwing errors - I have no idea if the Javascript is actually executing, because I can't get it to load my menus.

My pages are framed by two PHP include files, page_start.php and page_end.php. And smarty templates apparently choke horribly on PHP, despite being designed to work in PHP, which is a paradox that makes my brain hurt.

I did find somewhere where someone else had asked about this, and was told a smarty tag you could use to include a PHP file, but also given ominous warnings about how this could break the script. And I don't think that tag would work for me anyway, since the page_start.php include calls several other includes, in order to generate menus, a breadcrumb trail, etc.

IS there any reasonable way to get PHP to work in the templates? What, exactly, in a PHP file would break the script? Mine looks at where the page it's on is (via the $_SERVER['PHP_SELF'] variable) and generates the appropriate menus and breadcrumb trail accordingly. It probably doesn't need the breadcrumb trail within the directory, but it would be nice to be able to have some control over the menus.

Also, in the page_end.php include, it uses get_last_mod to generate a last modified date for the page. Again, probably not terribly relevant for the directory, and I could suppress it within this section with an if statement, but that would still require being able to execute PHP code...


Lynna

David
01-30-2006, 06:53 AM
I'm assuming you want it to run inside your other PHP created pages.
Here is an example of a directory running inside of OSCommerce.
{Unfortunately they no longer use the script}
I assume you are looking for something like this. I can get the person that did this to do it for you, but I know it will take him a little time (in other words not free). Let me know if you want me to try to get him to help.

Thanks,
David

spidersilk
01-30-2006, 07:57 AM
Unfortunately, the site this directory is on is a personal project, not a commercial site, so hiring someone to do anything with it is not an option. And I'd rather learn how to do it myself anyway.

From looking at that site, it looks he called the directory into osCommerce with an include -- it's even got the doctype, HTML, head and body tags all duplicated in it, which is horribly invalid document structure, but doesn't actually appear to be breaking anything.

Maybe I should try doing it that way -- including the directory in my page structure rather than my page structure in the directory. I'm just worried about the way it adds in all the head content and what not in the middle of the page. But then, I suppose that could potentially all be stripped out of the header template, couldn't it?

The only thing I'm not clear on is how you'd deal with all the other pages. Embedding the index page in an existing PHP file would be easy enough, but the only way I could see of embedding all the other pages would be to make a separate page within which to embed each one of them and then go through all the code of the script and change all the links, which seems like a huge headache. There's got to be a shortcut, I'm just not sure offhand what it would be...

Well, it's given me some new ideas to play around with, anyway - thanks!