modules for the templating language
| From: | Paras Dagli | Date: | Fri, 18 Feb 2000 05:27:49 +0000 |
| Subject: | modules for the templating language | ||
| Groups: | php.template | ||
| Request: | Send a blank email to php-template+get-139@lists.php.net to get a copy of this message | ||
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
Attachment: [text/x-vcard] Paras Dagli.vcf
Attachment: [text/x-vcard] Paras Dagli.vcf