Jump to content

Newbie question about templating


stegalex

Recommended Posts

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.