stegalex Posted November 28, 2007 Share Posted November 28, 2007 Please excuse the rookie question but I am having difficulty finding what I am looking for. I am in the process of learning PHP after many years of using Perl (specifically HTML::Embperl::Object) to do all my site work and while PHP has some nice features, there is one nice Embperl templating aspect that I haven't been able to find in my PHP studies. If you can help me figure it out, I would appreciate it. In Embperl::Object you create a "base" page that is the template from which all other pages inherit. In the base page, you do things like connect to the database, establish your page layout, copy in headers and footers, and stuff you don't want to have to worry about putting into every single page. Once you have your base page in a server directory, you don't have to worry about including headers, footers, etc in each web page. For example: if I establish my base.epl file as follows (see bolded line): <html><head><title>Mytitle</title></head> <body> [- # connect to database # print page header # left nav bar -] [- Execute ('*') -] [- # db disconnect # page footer -] </body> </html> Then I can establish a file called whatever I like (in this case "merkin.html") and Embperl will put the code in the location of the * in the previous example. The nice thing is that there is no need to include headers etc in the merkin.html file. merkin.html [- $req=shift -] # brings in the request object your content here. How do I do this in PHP? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/79249-newbie-question-about-templating/ Share on other sites More sharing options...
fenway Posted November 28, 2007 Share Posted November 28, 2007 Sounds like a glorified include. Quote Link to comment https://forums.phpfreaks.com/topic/79249-newbie-question-about-templating/#findComment-401155 Share on other sites More sharing options...
stegalex Posted November 28, 2007 Author Share Posted November 28, 2007 Hardly. The whole point is to find a way to avoid having to put include statements in every single page. Are you telling me that PHP does not have a way to do this? I have a hard time believing that PHP would require me to include mundane stuff like the database connection in EVERY single page request. Seems pretty cluttered. Quote Link to comment https://forums.phpfreaks.com/topic/79249-newbie-question-about-templating/#findComment-401167 Share on other sites More sharing options...
fenway Posted November 28, 2007 Share Posted November 28, 2007 What do you think Embedperl is doing with that fancy syntax? Having never used PHP ever, I can't really say. Quote Link to comment https://forums.phpfreaks.com/topic/79249-newbie-question-about-templating/#findComment-401200 Share on other sites More sharing options...
stegalex Posted November 28, 2007 Author Share Posted November 28, 2007 I don't understand your question. What Embperl is doing with the syntax is saving me from having to put includes on every page. How is this done in PHP without putting the same includes on each page? Quote Link to comment https://forums.phpfreaks.com/topic/79249-newbie-question-about-templating/#findComment-401211 Share on other sites More sharing options...
trq Posted November 28, 2007 Share Posted November 28, 2007 Im not sure exactly what EmbPerl is, but it sounds like its simply a higher level framework than what php itself actually is. There are many, many frameworks for php that will do bassically what you want, or you could build your own. But php itself seems a bit lower level then EmbPerl. Isn't EmbPerl just a framework based around mod_prel? You'll be looking for a php framework based around mod_php. Quote Link to comment https://forums.phpfreaks.com/topic/79249-newbie-question-about-templating/#findComment-401243 Share on other sites More sharing options...
Daniel0 Posted November 28, 2007 Share Posted November 28, 2007 I don't understand your question. What Embperl is doing with the syntax is saving me from having to put includes on every page. How is this done in PHP without putting the same includes on each page? fenway is talking about what it is doing behind the scenes. You might want to check out Smarty (http://smarty.php.net/) for templating. Quote Link to comment https://forums.phpfreaks.com/topic/79249-newbie-question-about-templating/#findComment-401265 Share on other sites More sharing options...
steelmanronald06 Posted November 28, 2007 Share Posted November 28, 2007 yeah, and for the includes check out php_auto_prepend and php_auto_append which are apache commands and go in a .htaccess Quote Link to comment https://forums.phpfreaks.com/topic/79249-newbie-question-about-templating/#findComment-401290 Share on other sites More sharing options...
trq Posted November 29, 2007 Share Posted November 29, 2007 which are apache commands and go in a .htaccess Correction, they are php directives and can go in either php.ini, .htaccess or httpd.conf. Quote Link to comment https://forums.phpfreaks.com/topic/79249-newbie-question-about-templating/#findComment-401803 Share on other sites More sharing options...
steelmanronald06 Posted November 29, 2007 Share Posted November 29, 2007 yeah, but sometimes it is (A) easier just to put in .htaccess and not worry about screwing up something in php.ini or httpd.conf, and (B) if you have a host then most of the time, unless it is a server, they won't let you do anything but add .htaccess (which is rare). Since it is the first time he has heard of it, I just gave him the easiest, and most likely, option. Quote Link to comment https://forums.phpfreaks.com/topic/79249-newbie-question-about-templating/#findComment-402057 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.