I found (after 2-3 Projects using PW) that it's a good technique to use templates in a way I think hasn't been thought of yet really by some. (Although the CMS we use at work for year, works this way.) I'm sure I'm maybe wrong and someone else is already doing something similar. But I wanted to share this for everybody, just to show alternative way of using the brillant system that PW is.
Delegate Template approach
I tend to do a setup like this:
- I create a main.php with the main html markup, no includes. So the whole html structure is there.
- I then create page templates in PW without a file associated. I just name them let's say: basic-page, blog-entry, news-entry... but there's no basic-page.php actually.
- Then after creating the template I make it use the "main" as alternative under "Advanced" settings tab. So it's using the main.php as the template file.
- This allows to use all templates having the same php master template "main.php"
- Then I create a folder and call it something like "/site/templates/view/", in which I create the inc files for the different template types. So there would be a basic-page.inc, blog-entry.inc ...
- Then in the main.php template file I use following code to delegate what .inc should be included depending on the name of the template the page requested has. Using the TemplateFile functions you can use the render method, and assign variables to give to the inc explicitly, or you could also use just regular php include() technic.
<?php
/*
* template views depending on template name
* using TemplateFile method of PW
*/
// delegate render view template file
// all page templates use "main.php" as alternative template file
if( $page->template ) {
$t = new TemplateFile($config->paths->templates . "view/{$page->template}.inc");
//$t->set("arr1", $somevar);
echo $t->render();
}
<?php
/*
* template views depending on template name
* using regular php include
*/
if( $page->template ) {
include($config->paths->templates . "view/{$page->template}.inc");
}
I chosen this approach mainly because I hate splitting up the "main" template with head.inc and foot.inc etc. although I was also using this quite a lot, I like the delegate approach better. Having only one main.php which contains the complete html structure makes it easier for me to see/control whats going on.
Hope this will be useful to someone. Cheers