Date: 10/10/00
- Next message: Omar Cromwell Mercado: "[phplib-dev] SOS: Invalid SQL Error"
- Previous message: uw: "[phplib-dev] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: uw
Date: Tue Oct 10 14:32:02 2000
Modified files:
php-lib/php/ext/integratedtemplate.inc
Log message:
- added some more phpdoc compilant documentation
Index: php-lib/php/ext/integratedtemplate.inc
diff -u php-lib/php/ext/integratedtemplate.inc:1.4 php-lib/php/ext/integratedtemplate.inc:1.5
--- php-lib/php/ext/integratedtemplate.inc:1.4 Tue Oct 10 13:35:14 2000
+++ php-lib/php/ext/integratedtemplate.inc Tue Oct 10 14:31:31 2000
@@ -3,9 +3,70 @@
* Integrated Template - IT
*
* Well there's not much to say about it. I needed a template class that
-* supports a single template file with multiple (nested) blocks inside.
+* supports a single template file with multiple (nested) blocks inside and
+* a simple block API.
*
+* The Isotemplate API is somewhat tricky for a beginner although it is the best
+* one you can build. template::parse() [phplib template = Isotemplate] requests
+* you to name a source and a target where the current block gets parsed into.
+* Source and target can be block names or even handler names. This API gives you
+* a maximum of fexibility but you always have to know what you do which is
+* quite unusual for php skripter like me.
+*
+* I noticed that I do not any control on which block gets parsed into which one.
+* If all blocks are within one file, the script knows how they are nested and in
+* which way you have to parse them. IT knows that inner1 is a child of block2, there's
+* no need to tell him about this.
+*
+* <table border>
+* <tr>
+* <td colspan=2>
+* __global__
+* <p>
+* (hidden and automatically added)
+* </td>
+* </tr>
+* <tr>
+* <td>block1</td>
+* <td>
+* <table border>
+* <tr>
+* <td colspan=2>block2</td>
+* </tr>
+* <tr>
+* <td>inner1</td>
+* <td>inner2</td>
+* </tr>
+* </table>
+* </td>
+* </tr>
+* </table>
+*
+* To add content to block1 you simply type:
+* <code>$tpl->setCurrentBlock("block1");</code>
+* and repeat this as often as needed:
+* <code>
+* $tpl->setVariable(...);
+* $tpl->parseCurrentBlock();
+* </code>
+*
+* To add content to block2 you would type something like:
+* <code>
+* $tpl->setCurrentBlock("inner1");
+* $tpl->setVariable(...);
+* $tpl->parseCurrentBlock();
+*
+* $tpl->setVariable(...);
+* $tpl->parseCurrentBlock();
+*
+* $tpl->parse("block1");
+* </code>
+*
+* This will result in one repition of block1 which contains two repitions
+* of inner1. inner2 will be removed if $removeEmptyBlock is set to true which is the default.
+*
* Usage:
+* <code>
* $tpl = new IntegratedTemplate( [string filerootdir] );
*
* // load a template or set it with setTemplate()
@@ -14,21 +75,22 @@
* // set "global" Variables meaning variables not beeing within a (inner) block
* $tpl->setVariable( string variablename, mixed value );
*
-* // like with the Isotopp Templates there's a second way to use setVariable()
+* // like with the Isotemplates there's a second way to use setVariable()
* $tpl->setVariable( array ( string varname => mixed value ) );
*
* // Let's use any block, even a deeply nested one
* $tpl->setCurrentBlock( string blockname );
*
-* // repeat this as often as you neer.
+* // repeat this as often as you need it.
* $tpl->setVariable( array ( string varname => mixed value ) );
* $tpl->parseCurrentBlock();
*
* // get the parsed template or print it: $tpl->show()
* $tpl->get();
+* </code>
*
* <email protected> Ulf Wendel <uw <email protected>>
-* <email protected> 1.1 28/09/00
+* <email protected> 1.2 10/10/00
* <email protected> public
*/
class IntegratedTemplate {
@@ -101,10 +163,25 @@
/**
* Full RegExp used to find variable placeholder, filled by the constructor.
- * <email protected> string Looks somewhat like @(delimiter varname delimiter)@
+ * <email protected> string Looks somewhat like @(delimiter varname delimiter)@
+ * <email protected> public
* <email protected> IntegratedTemplate()
*/
var $variablesRegExp = "";
+
+ /**
+ * Controls the handling of unknown variables, default is remove.
+ * <email protected> boolean
+ * <email protected> public
+ */
+ var $removeUnknownVariables = true;
+
+ /**
+ * Controls the handling of empty blocks, default is remove.
+ * <email protected> boolean
+ * <email protected> public
+ */
+ var $removeEmptyBlocks = true;
/**
* Full RegExp used to find blocks an their content, filled by the constructor.
@@ -176,18 +253,6 @@
var $clearCacheOnParse = true;
/**
- * Controls the handling of unknown variables, default is remove.
- * <email protected> boolean
- */
- var $removeUnknownVariables = true;
-
- /**
- * Controls the handling of empty blocks, default is remove.
- * <email protected> boolean
- */
- var $removeEmptyBlocks = true;
-
- /**
* Root directory for all file operations.
* The string gets prefixed to all filenames given.
* <email protected> string
@@ -222,7 +287,6 @@
$this->blockRegExp = '@!--\s+BEGIN\s+('.$this->blocknameRegExp.')\s+-->(.*)<!--\s+END\s+\1\s+--> <email protected>';
$this->setRoot($root);
-
} // end constructor
/**
@@ -479,17 +543,24 @@
/**
* Reads a template file from the disk.
*
- * <email protected> string name of the template file, full path!
- * <email protected> boolean remove unknown/unused variables?
- * <email protected> boolean remove empty blocks?
+ * <email protected> string name of the template file
+ * <email protected> mixed How to handle unknown variables. true = remove, false = keep,
+ * empty string = fallback to class default $removeUnknownVariables.
+ * <email protected> mixed How to handle empty blocks. true = remove, false = keep,
+ * empty string = fallback to class default $removeEmptyBlocks
* <email protected> public
* <email protected> boolean false on failure, otherwise true
- * <email protected> $template, setTemplate()
+ * <email protected> $template, setTemplate(), $removeUnknownVariables, $removeEmptyBlocks
*/
- function loadTemplatefile($filename, $removeUnknownVariables = true, $removeEmptyBlocks = true) {
+ function loadTemplatefile($filename, $removeUnknownVariables = "", $removeEmptyBlocks = "") {
$template = $this->getfile($filename);
-
+
+ if (""!=$removeUnknownVariables)
+ $this->removeUnknownVariables = ($removeUnknownVariables) ? true : false;
+ if (""!=$removeEmptyBlocks)
+ $this->removeEmptyBlocks = ($removeEmptyBlocks) ? true : false;
+
return $this->setTemplate($this->getFile($filename), $removeUnknownVariables, $removeEmptyBlocks);
} // end func LoadTemplatefile
---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-dev-unsubscribe <email protected>
For additional commands, e-mail: phplib-dev-help <email protected>
- Next message: Omar Cromwell Mercado: "[phplib-dev] SOS: Invalid SQL Error"
- Previous message: uw: "[phplib-dev] cvs commit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

