PHP Classes

File: ex2.p

Recommend this page to a friend!
  Classes of barnabás debreceni   XTemplate   ex2.p   Download  
File: ex2.p
Role: ???
Content type: text/plain
Description: example 2 (demonstrates nested blocks)
Class: XTemplate
Template engine for PHP
Author: By
Last change:
Date: 24 years ago
Size: 1,181 bytes
 

Contents

Class file image Download
<? /* example 2 demonstrates multiple level dynamic blocks */ require "xtpl.p"; $xtpl=new XTemplate ("ex2.xtpl"); /* you can reference to array keys in the template file the following way: {DATA.ID} or {DATA.NAME} say we have an array from a mysql query with the following fields: ID, NAME, AGE */ $rows[1]=array( /* add some data */ ID=>"38", NAME=>"cranx", AGE=>"20" ); $rows[2]=array( /* add some data */ ID=>"27", NAME=>"ozsvar", AGE=>"34" ); $rows[3]=array( /* add some data */ ID=>"56", NAME=>"alpi", AGE=>"23" ); for ($i=1;$i<=3;$i++) { $xtpl->assign("DATA",$rows[$i]); /* assign array data */ $xtpl->assign("ROW_NR",$i); $xtpl->parse("main.table.row"); /* parse a row */ /* another way to do it would be: $xtpl->insert_loop("main.table.row",array( DATA=>$rows[$i], ROW_NR=>$i )); */ } $xtpl->parse("main.table"); /* parse the table */ $xtpl->parse("main"); $xtpl->out("main"); ?>