you're reading...
IT-Center, PHP, Web Based

Pattemplate for PHP, call template in different page

Can I re-use templates in different pages?

Of course you can. Let’s say you’v got a footer and a header, which should be the same in all of your pages, so you have to change it only once and it will be updated in all pages. To accomplish this, at first create the two files, and save them to your template directory as header.tmpl and footer.tmpl. The templates could look like this:

<patTemplate:tmpl name="header">
  <h1>My Superhero database</h1>

and this

<patTemplate:tmpl name="footer">
<span class="footer">Superhero database was last updated on 2001-12-24 (Oh, christmas).</span>

Now you may include these two files in all other pages by using the src attribute of the <patTemplate:tmpl> tag:

<patTemplate:tmpl name="page">
    <title>Any page of the superhero database</title>
    <patTemplate:tmpl name="includedHeader" src="header.tmpl" parse="on"/>
    Here is the rest of the page...
	Can be anything from static HTML to other templates.
    <patTemplate:tmpl name="includedFooter" src="footer.tmpl" parse="on"/>

You may adress the header and footer templates as if the were written directly into the page but you have to change them only once, so this is some kind of include() for templates.


About berbagisolusi

Berbagi merupakan sebuah bentuk simbol keikhlasan untuk membantu dan menolong, sedangkan solusi adalah cara menyelesaikan masalah. Setiap manusia pasti mengalami masalah, tetapi kita tidak perlu mengalami masalah yang sama jika orang lain pernah mengalami dan kita tahu hal tersebut.


No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 10 other followers

April 2014
« Oct   Jun »


Web Statistic

Blog Stats

  • 160,987 hits
%d bloggers like this: