Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


FastTemplate Substitution

September 22, 2000

Now you want FastTemplate to substitute all your {MACROS} with their respective values in the template foo. Issue the command

<?php $tpl->parse(PAGECONTENT"foo"); ?> 

to do that. This command will assign the content of the template "foo" to the unique name PAGECONTENT.

Of course, we are not done with that yet since the template bar holds the main page definition and FastTemplate needs to substitute the macro {PAGECONTENT} in it. We also need to assign a PAGETITLE and to do that we say:

<?php

$tpl->assign(PAGETITLE"FooBar test");
$tpl->parse(MAIN"bar");

?>

Easy, is not it? We just need to print it out now:

<?php

$tpl->FastPrint(MAIN);

?>

The following three files show how the more verbose description looks in practice. I would not know how to live without this technique in real life - your designers will be happy and your boss will smile, because you can do more things in less time.

bar.tpl

<!-- bar.tpl -->
<HTML>
<HEAD><TITLE>Feature world - {PAGETITLE}</TITLE></HEAD>
<BODY BGCOLOR=BLACK TEXT=WHITE>
<H1>{PAGETITLE}</H1>
{PAGECONTENT}
</BODY>
</HTML>

foo.tpl

<!-- foo.tpl -->
This does not do anything obvious. Please look at {NAME}.

demo.php3

<?php

include "class.FastTemplate.php3";

$tpl = new FastTemplate(".");
$tpl->define(array(foo => "foo.tpl"bar => "bar.tpl"));

$tpl->assign(NAME"me");
$tpl->assign(PAGETITLE"Welcome!");

$tpl->parse(PAGECONTENT"foo");
$tpl->parse(MAIN"bar");

$tpl->FastPrint(MAIN);

?>

Templates - why and how to use them in PHP3
Templates - why and how to use them in PHP3
Building Whole Tables


Up to => Home / Authoring / Languages / PHP / Templates




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers