modules for the templating language
[email protected] ("Paras Dagli") Thu, 17 Feb 2000 21:27:49 -0800
| Newsgroups | php.template |
|---|---|
| Message-ID | <[email protected]> |
I have copied over Dan's templating language example and put it an example
of how modules could be implemented.
**************************
moduleNames.php
<?php
// Define and parse template.
$tmpl = tmpl_define("moduleNames.tmpl");
// Omitted: Query DB or otherwise obtains some results.
// Assign # of results (scalar)
tmpl_assign($tmpl, "num_found", "3");
// Assign the results. An array of first names and an array of last names.
tmpl_assign($tmpl, "fname", array("Dan", "John", "Homer"));
tmpl_assign($tmpl, "lname", array("Libby", "Doe", "Simpson"));
// Assign a page background color and font.
tmpl_assign($tmpl, array(page_bgcolor => "red",
default_font => "arial",
default_size => "+2") );
?>
**************************
moduleNames.tmpl
<HTML>
<body bgcolor="{{page_bgcolor}}">
<font face="{{default_font}}" size="{{default_size}}">
found {{num_found}} results.
<TABLE>
<TR><TD>First Name</TD><TD>Last Name</TD></TR>
<!-- Begin list of names -->
{{section:names}}
<TR><TD>{{fname}}</TD><TD>{{lname}}</TD></TR>
{{/section:names}}
<!-- End list of names -->
</TABLE>
</font>
</body>
</HTML>
**************************
addressBook.php
<?php
// Include header file for modules
tmpl_headerFile("modules.inc");
// Print other modules, or whatever else
// If there is a module for First Name, Last Name then print that
// otherwise we do the DB query, php parsing, variable assigning, ....
{:if FIRSTLASTNAME}
// Retrieve buffer with variables inserted, and print.
print tmpl_getbuf(FIRSTLASTNAME);
{:else}
// no module, so do we do what should happen in moduleNames.php
// like DB query, variable assignment, ...
{/:endif}
?>
**************************
modules.inc
<:defineModule name=FIRSTLASTNAME>
php: moduleNames.php;
tmpl: moduleNames.tmpl;
</:defineModule>
paras
Paras Dagli.vcf
(text/x-vcard, 445 B)
BEGIN:VCARD VERSION:2.1 N:Dagli;Paras FN:Paras Dagli NICKNAME:paras ORG:Epinions Inc.;Engineering TITLE:Verbalkint TEL;WORK;VOICE:650-210-2328 TEL;WORK;FAX:650-210-0710 ADR;WORK:;;2037 Landings Drive;Mountain View;CA;94043;USA LABEL;WORK;ENCODING=QUOTED-PRINTABLE:2037 Landings Drive=0D=0AMountain View, CA 94043=0D=0AUSA URL: URL:http://www.epinions.com/user-verbalkint EMAIL;PREF;INTERNET:[email protected] REV:19991209T095210Z END:VCARD