Topic: Importing EE templates into PHP

So I've got an old PHP script that works great, and I don't want to re-make it for EE, so I'm just going to put it in a folder and run the script from there.

now to keep all the style and everything consistent with the rest of the site I just want to import my header and footer templates right into the script so I don't have to actually copy and paste the HTML in there.  Plus if anything changes in teh future, this is updated as well.

so in PHP I figured I could just do a include() and just go right to the template: http://hilandpark.org/site/header

include ("http://hilandpark.org/site/header");

When I do that, it just returns a white page with no source code.  What's the deal with that?

How can I just include  the HTML from a page into a PHP script?

Re: Importing EE templates into PHP

There's a configuration setting in PHP -- "URL fopen wrappers" -- that determines whether or not you can include files via "http://". If this isn't set correctly, or if you're running on a Windows server, this might be causing the error.

Check the PHP documentation for more info: http://us.php.net/include/

Last edited by opus (2008-05-14 12:00:04)

I feel a nostalgia for an age yet to come...

Re: Importing EE templates into PHP

Also, have you thought about including that PHP include into your EE templates? Basically, doing it the other way around?

I feel a nostalgia for an age yet to come...

Re: Importing EE templates into PHP

Well I added a php.ini file and it's already set correctly to: allow_url_fopen = On

I tried it again, and I also tried the following and got nothing.

fopen("http://hilandpark.org/site/header", "r");

I know EE supports using PHP tags, I tried that and turned on PHP for that template and it just spit out all the PHP code on the page.  Maybe there's something else I need to do for that to work?

Re: Importing EE templates into PHP

Well I figured out part of the problem!  PHP is assuming that /site/header is a directory list, and it's giving me errors about these directories not existing.

Ok, so is there a way in EE to get a "normal" looking URL that I can link to a certain template to make PHP happy?  Something like /index.php?template=header

Re: Importing EE templates into PHP

Perhaps if you have URL Query Strings turned on in EE. However, that will affect the entire site, which may not be desirable.

I feel a nostalgia for an age yet to come...

Re: Importing EE templates into PHP

C.Barr wrote:

Well I figured out part of the problem!  PHP is assuming that /site/header is a directory list, and it's giving me errors about these directories not existing.

Ok, so is there a way in EE to get a "normal" looking URL that I can link to a certain template to make PHP happy?  Something like /index.php?template=header

I have no idea how you have your templates setup, but what about when your editing the template it has the option to render it. What about using the URL from that? Maybe some EE Gurus (Boyink) will have some better info on this.

Re: Importing EE templates into PHP

the "view rendered template" button just takes you to the same page everyone else sees I believe.

What I ended up deciding to do was go to the template, copy the source to an HTML file and just include that.  It won't be automatically updated if I make a change to the templates, but it's not a big deal to do.

I probably should have just done this from the beginning.  Thanks everyone.