PHP Classes

File: example/example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Classes of Helmut Daschnigrum  >  DirecTemplate  >  example/example.php  >  Download  
File: example/example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: DirecTemplate
Template engine based on regular expressions
Author: By
Last change:
Date: 8 years ago
Size: 2,615 bytes


Class file image Download
/* DirecTemplate - Simple, efficient template system
 * Version 1.1.1
 * Copyright 2003-2005, Steve Blinch
 * ============================================================================
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA


// instantiate the template
$tpl = &new Template();

// set the path to the template directory
$tpl->template_dir = dirname(__FILE__)."/templates/";

// In order to display dynamic text in a template, we put placeholders
// such as "{$title}" in the template file. Then, we use $tpl->assign() to
// bind a variable to that placeholder.
// So if, in your template (header.tpl), you have the following:
// <title>{$title}</title>
// Then it will be replaced with:
// <title>DirecTemplate example</title>

// bind the words "DirecTemplate example" to the "title" placeholder
$tpl->assign("title","DirecTemplate example");
// display "header.tpl" (located in the "templates" directory)

// set a couple of sample strings
$name = "John Smith";
$phone = "555-555-1234";
$email = "";
$company = "John Smith & Sons";

// setup a sample array containing a number of ficticious products
$products = array(
"purple" => array(
"name"=>"Purple Widget"
"blue" => array(
"name"=>"Blue Widget"
"red" => array(
"name"=>"Red Widget"

// next, we bind the variables above to the template class

// then, display the order - please refer to order.tpl for details

// and finally, display the footer