Web Producer w/ Brilliance
Aquent
US-CA-San Rafael

Justtechjobs.com Post A Job | Post A Resume

Templates - Why and How To Use Them In PHP3
Are you faced with the task of creating a site which should be programmed by a coder (namely you) and designed by a designer? Do not you know how to make the life easy for both of you? I have got the answer for you: Use FastTemplate to make your site more customizable!
Ok, you probably want to know why you want to use FastTemplates.
  • change the look of your entire web site in seconds
  • abstract programming without dirty HTML
  • the designer does not need to take care of all that "fuzzy" code
  • it is amazingly fast
  • easier reuse of old templates (think of common forms)
FastTemplate is derived from a similar named Perl packet (can be found on CPAN). You can download the PHP port from its homepage. You just need one class file (class.FastTemplate.php3) from it.
Let me explain first that there is a difference between creating a page using templates and simply spitting it out by using echo or print. The simple echo/print approach is great for writing short scripts, but leaves you alone with better organization or customization. Templates on the other hand give you the ability to create multiple language sites by just changing one parameter. They force you to pay attention to what you do.
Do not be afraid of thinking before you start coding. It may take some time, but this time will be given back to you after your project grows in size.
So, how does one utilize FastTemplate? You need to start with a simple call to
<?php $tpl = new FastTemplate("path"); ?>
passing it the path to the template directory where all your template files live. It returns an object which you can use to assign parameters, create pages and so on.
FastTemplate is based on the assumption that a large page is built out of many small parts. Every part has a unique name. The smallest part is a normal text string which is assigned to such a unique name. This is done by
<?php $tpl->assign(NAME, "text"); ?>
. Now, FastTemplate knows what you mean, if one of your templates contains
{NAME}
Additionally, FastTemplate needs to know how you want to call your templates. You need to give it a hint by passing an associative array to
<?php $tpl->define(); ?>
<?php $tpl->define(array(foo => "foo.tpl", bar => "bar.tpl")); ?>
This assigns the name foo and bar to the respective files (namely foo.tpl and bar.tpl).
[ Next Page ]


Comments:
Removing the {} around textsmallbadad09/28/05 12:31
RE: ROOT dir [./] is not a directory Alex Mendes09/15/05 01:05
Functions to insert colors in PHPAnkush07/26/05 02:15
Functions for color coding in PHPAnkush07/26/05 02:08
PHP Article PlacementTom Wille12/15/04 13:25
foobarunknows06/02/03 12:52
RE: PHP4 errorMike Smith11/08/02 12:21
how to handle variables?Torsten11/01/02 18:29
Pb with fast templates on web serverAlex10/30/02 06:35
RE: ROOT dir [./] is not a directory Manuela Kiesenhofer09/18/02 05:03
RE: Curly braces remain after parsingAnna09/12/02 02:10
RE: Using Framesets within FastTemplateOctavi Fors09/10/02 08:07
Creating TemplateLili08/30/02 06:57
RE: why not use XML + XLST?Koen Pellegrims08/23/02 06:47
RE: take html seriously and fire the designersJohn McBride08/19/02 10:28
Using Framesets within FastTemplateChristian Drganc08/15/02 07:53
Quotes in FastTemplateRenato Neves07/30/02 12:55
RE: Je veux telechager ...Bruno07/22/02 15:55
RE: why not use XML + XLST?Bruno07/22/02 15:44
RE: why not use XML + XLST?Michael07/16/02 10:52
php_oci8.dllTarun07/16/02 02:20
why not use XML + XLST?avatar avatralis06/30/02 13:12
NestingRaul Carvalho06/21/02 12:17
PHP4 errorkim jong chul06/12/02 00:37
Dynamic blocks & PHP4ptha06/08/02 08:24
ROOT dir [./] is not a directory Rubble05/23/02 15:32
clear unassigned variablesAlex04/01/02 07:19
RE: conditions in templatesChristopher Brown-Floyd03/16/02 10:12
RE: How to use fasttemplate on windowsDipak03/13/02 10:07
phplibLauren Matheson03/12/02 00:21
Basic ExplanationSachin Malekar03/07/02 06:30
RE: An example that worksChristopher Brown-Floyd02/21/02 23:04
conditions in templateschangpeng02/21/02 00:09
An example that worksJohn 02/19/02 22:37
dynamic display of databse fields?wirre evers02/15/02 08:36
Je veux telechager ...hamza02/09/02 14:41
RE: PHP4 -> my correctionVince02/05/02 17:41
Dynamically defined templatesBjørn Danielsen02/02/02 02:36
Solution: php4 errorBlankLee01/12/02 06:26
RE: PHP4 errorMarshall12/19/01 19:47
RE: take html seriously and fire the designersTobias Beuving12/17/01 11:32
RE: take html seriously and fire the designersCygnus12/01/01 12:22
take html seriously and fire the designersmagister ludi11/23/01 02:03
RE: PHP4 errorMarkku Leitso11/21/01 13:21
RE: how to use PHP in template fileNemo11/05/01 14:37
why should i use FastTemplate?Andres Peter11/05/01 08:59
RE: Another correction using php 4.0Phil11/01/01 04:07
RE: It's not working with PHP4ray10/31/01 09:33
RE: "Real" FastTemplates site exampler0d10/20/01 00:49
RE: examples of sites using Fast Templates Adonis09/17/01 03:47
RE: table with alternating color lines in templ.Oliver09/12/01 02:25
RE: how to use PHP in template filenghia09/11/01 09:50
ERROR: get_template() failure: [./] Engi09/10/01 04:09
Template IssuesJerome Howard09/07/01 07:50
RE: how to use PHP in template fileCyberSliver09/03/01 05:50
ERROR: get_template() failure: [./] Mick van der Most van Spijk08/30/01 00:46
ERROR: get_template() failure: [./] teku08/29/01 15:13
Checkboxes?Tony Castelletto08/21/01 08:50
RE: It's not working with PHP4Velcroe08/17/01 15:26
RE: Curly braces remain after parsingCorey Grusden08/14/01 21:47
Bannerwerbung wie in php nukeAlex08/03/01 07:26
problem using templateprasanna08/01/01 05:32
RE: Curly braces remain after parsingSteve Hajducko07/26/01 12:21
best , fast , usefullWill07/24/01 14:41
examples of sites using Fast Templates jason matta07/23/01 23:39
It won't work at allRobin Message07/18/01 14:02
RE: It's not working with PHP4bread07/18/01 08:43
eregExp Problems - curly bracesMoMad07/16/01 14:53
RE: It's not working with PHP4linearTOY07/09/01 13:36
PHP4 -> my correctionConrad07/07/01 06:24
what about javascriptsJeroen Olthof06/28/01 15:47
RE: Curly braces remain after parsingHector Lecuanda06/28/01 11:06
RE: Curly braces remain after parsingBrian06/27/01 07:19
RE: Curly braces remain after parsingBrian06/27/01 07:14
RE: Another correction using php 4.0Marcel06/26/01 20:19
ERROR: get_template() failure: [./] Paul Freeman06/18/01 09:15
Curly braces remain after parsingAdam Fast06/07/01 05:52
Is this a fastemplateOmega06/04/01 22:53
define_nofile() not ported, :-(((( !Vadim Bich05/19/01 10:50
Fatal error: Graham Lawes05/06/01 10:35
REPEATING ROWS IN TABLESJurgen Westerhof04/10/01 11:32
Double FastTemplate speedVincent Peace04/09/01 12:03
RE: how to use PHP in template fileSteen Rabol04/05/01 06:10
RE: how to use PHP in template fileEric Blade03/26/01 13:05
RE: Another correction using php 4.0Alejandro Huezo03/09/01 21:30
Does FastTemplate work with a database?sorin02/25/01 11:10
RE: Another correction using php 4.0Olivier fernandez02/19/01 02:35
RE: table with alternating color lines in templ.Concerned Programmer02/17/01 00:45
And another thing...Rubio02/16/01 07:20
RE: It's not working with PHP4Rubio02/16/01 03:21
FastTemplate pain (or How I spent my weekend)Mark02/13/01 09:01
RE: What's with that FOO anyway?Martin Kuplens-Ewart02/11/01 19:18
RE: It's not working with PHP4Hyper^T02/06/01 21:05
RE: What's with that FOO anyway?Bob Randell01/23/01 09:36
RE: What's with that FOO anyway?hross01/21/01 02:07
change assign function?assign function01/15/01 17:53
RE: table with alternating color lines in templ.Alin01/09/01 04:11
RE: What's with that FOO anyway?Corey Punches01/03/01 16:07
how to use PHP in template fileFatima01/02/01 19:22
Saving the page ...smoover01/02/01 07:48
table with alternating color lines in templ.Sergio12/28/00 12:33
table with alternating color lines in templ.Sergio12/28/00 12:31
Another correction using php 4.0Edwin Ortega12/27/00 11:47
A quick benchmarkKen Gregg12/20/00 15:09
RE: can i put html file? dennis 12/15/00 03:26
RE: setting this up(amateur at work)Aaron Heidel12/14/00 21:17
can i put html file? venkat12/13/00 04:04
This is great, but....Joris Van den Borre12/09/00 15:51
This is great, but....Tom 12/09/00 04:38
RE: It's not working with PHP4Graeme12/09/00 02:40
setting this up(amateur at work)Chris Dorr12/08/00 07:58
RE: What's with that FOO anyway?danny12/02/00 09:34
What's with that FOO anyway?Hans12/01/00 10:27
Why it can not show PHP page on my homepage?Thanate Namwises11/21/00 12:12
Parsing contents Problems (FastTemplate)John Young11/15/00 22:07
Configuration problemsDamian11/15/00 09:54
"Real" FastTemplates site exampleRonnie T. Moore10/25/00 02:03
RE: template driven websiteJohn Barker10/19/00 23:06
RE: It's not working with PHP4danny10/03/00 07:22
What the dot dozonhisham09/26/00 22:15
Cool Idea, Bad ExamplesJeremy Rempel08/06/00 21:50
RE: It's not working with PHP4Eric Chang08/05/00 01:52
It's not working with PHP4LEE, BUMSOOO07/30/00 07:06
template driven websitedipen07/08/00 05:16
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.