PHP Classes

File: template.php

Recommend this page to a friend!
  Classes of Jonathan Gotti   Block template   template.php   Download  
File: template.php
Role: Application script
Content type: text/plain
Description: sample template file
Class: Block template
Template engine based in the concept of blocks
Author: By
Last change: add some explanation regarding the new 'require' parameter for section inclusion
Date: 18 years ago
Size: 3,542 bytes


Class file image Download
put this file in ./template/default/

All text before the first section won't be parse and will be consider as comments.
You can comment any line in the file by starting it with a '#'

section are declared on a new line starting with @#SECTIONAME
section end at the start of the next section or at the end of the file
they can contain some vars like this @=var/=@ or like this @=var=@ var content @=/var=@
Vars can contain parameters like this: @=var param='value' /=@ and param values must be protected with single or double quotes.

Vars can be the name of a section in which case the section will be include in place of the tag
@=SECTIONAME/=@ you can add a '*' to the end of the sectioname (ie: @=SECTIONAME*/=@) to made it optionnal,
this mean that the section will be include only if at least one of its vars is filled else it won't.

A common use is to declare section in UPPERCASE, be aware that block template is case sensitive!
default : this param is used to set a default value for var replacement like this
            @=var default='default replacement value'/=@
tagcontent: is a special parameter that contain the var content for example:
            @=var=@ this is the tagcontent parameter value @=/var=@
parameter values can also be a sectioname!
require: name of minimal vars needed to include a section (used for optionnal section only), @=SECTIONINCLUDED require='var1,var2' /=@
- you can point any parameter to another by adding an '@' before the section name you want to point on it like this:
  @=var default='@tagcontent'=@ doing this the default value of var will be the tagcontent @=/var=@
- the default behaviour when parsing a template is to leave parameter untouch so if you have something like this:
  @=var default='@tagcontent'/=@ this is a tagcontent with a @=othervar default='test'/=@ in it@=/var=@
  it will be replaced by : "this is a tagcontent with a @=othervar default='test'/=@ in it" and @=othervar/=@ won't be replace.
  If you want to force the parameter parsing you can use the special 'preparse' parameter for this.
  @=var preparse='tagcontent,you,can,add,other,param,to,preparse,by,separating,them,with,coma' default='@tagcontent'/=@
    this is a tagcontent with a @=othervar default='test'/=@ in it
  this will be replaced by : 'this is a tagcontent with a test in it'

#- The BODY section is the only absolutely REQUIRED one!
<body @=bodyparams/=@
<div class='main'>
  <div class='header'>
  <div class='pagecontent'>
    #- content will contain all previoulsy added content (using methods add_*_content())

#- section starting by BOX are specials ones look box and add_box_content method for more details
<div class='box'>
  #- we want optionnal title for box section so we create a BOX_TITLE section to optionnaly include
  #- you may optionnaly include BOX_TITLE like this too
  # @=BOX_TITLE require='boxtitle'/=@
#- this section will be include only if a boxtitle is given
<h1 class='title'>@=boxtitle/=@</h1>
<div class='menu'>
<li><a href='@=url/=@'>@=label/=@</a></li>

@=BOX boxtitle='news' boxcontent='@newscontent'/=@
<a href='@=url/=@'>@=title/=@</a><br />