cvs: pear /HTML_Template_Xipe/docs/fullFeatured index.php index.tpl /HTML_Template_Xipe/docs/fullFeatured/tmp .htaccess
/HTML_Template_Xipe/docs/includes include.mcr include.tpl include1.mcr include1.tpl index.php index.tpl /HTML_Template_Xipe/docs/includes/tmp
.htaccess
| From: | Wolfram Kriesing | Date: | Mon, 10 Feb 2003 22:19:09 +0000 |
| Subject: | cvs: pear /HTML_Template_Xipe/docs/fullFeatured index.php index.tpl /HTML_Template_Xipe/docs/fullFeatured/tmp .htaccess /HTML_Template_Xipe/docs/includes include.mcr include.tpl include1.mcr include1.tpl index.php index.tpl /HTML_Template_Xipe/docs/includes/tmp .htaccess |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-8806@lists.php.net to get a copy of this message | ||
cain Mon Feb 10 17:19:09 2003 EDT
Added files:
/pear/HTML_Template_Xipe/docs/includes include.mcr include.tpl
include1.mcr include1.tpl
index.php index.tpl
/pear/HTML_Template_Xipe/docs/includes/tmp .htaccess
/pear/HTML_Template_Xipe/docs/fullFeatured index.php index.tpl
/pear/HTML_Template_Xipe/docs/fullFeatured/tmp .htaccess
Log:
- moved here
Index: pear/HTML_Template_Xipe/docs/includes/include.mcr +++ pear/HTML_Template_Xipe/docs/includes/include.mcr <!--// // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // $Id: include.mcr,v 1.1 2003/02/10 22:19:08 cain Exp $ //--> {%include include1.mcr%} {%macro include_text()%} <br><br> this is text from the macro \{%include_text()%\} which is in the file <b>include.mcr</b> <br> {%include1_text()%} {%endmacro%} Index: pear/HTML_Template_Xipe/docs/includes/include.tpl +++ pear/HTML_Template_Xipe/docs/includes/include.tpl <!--// // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // $Id: include.tpl,v 1.1 2003/02/10 22:19:08 cain Exp $ //--> <br> i am a text from include.tpl <br> {%include include1.tpl%} Index: pear/HTML_Template_Xipe/docs/includes/include1.mcr +++ pear/HTML_Template_Xipe/docs/includes/include1.mcr <!--// // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // $Id: include1.mcr,v 1.1 2003/02/10 22:19:08 cain Exp $ //--> {%macro include1_text()%} <br><br> this is text from the macro \{%include1_text()%\} which is in the file <b>include1.mcr</b> <br> {%endmacro%} Index: pear/HTML_Template_Xipe/docs/includes/include1.tpl +++ pear/HTML_Template_Xipe/docs/includes/include1.tpl <!--// // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // $Id: include1.tpl,v 1.1 2003/02/10 22:19:08 cain Exp $ //--> <br> i am a text from include1.tpl <br> Index: pear/HTML_Template_Xipe/docs/includes/index.php +++ pear/HTML_Template_Xipe/docs/includes/index.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // $Id: index.php,v 1.1 2003/02/10 22:19:08 cain Exp $ ini_set('include_path',realpath(dirname(__FILE__).'/../../../../../').':'.realpath(dirname(__FILE__).'/../../../../../../includes').':'.ini_get('include_path')); ini_set('error_reporting',E_ALL); // // include the files needed // require_once('HTML/Template/Xipe.php'); require_once('HTML/Template/Xipe/Filter/Basic.php'); // // make template class instance // $options = array( 'templateDir' => dirname(__FILE__) ,'compileDir' => 'tmp' // use the compile dir 'tmp' under the template dir ,'autoBraces' => false ,'forceCompile'=>true //,'filterLevel'=>9 ); $tpl = new HTML_Template_Xipe($options); // fill some vars $nums = array('one','two','three'); // // show the template // $tpl->compile('index.tpl'); include($tpl->getCompiledTemplate()); ?> Index: pear/HTML_Template_Xipe/docs/includes/index.tpl +++ pear/HTML_Template_Xipe/docs/includes/index.tpl <!--// // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // $Id: index.tpl,v 1.1 2003/02/10 22:19:08 cain Exp $ //--> {%include include.mcr%} <html> <head> <title>Example - HTML_Template_Xipe - includes</title> <link href="../style.css" type="text/css" rel="StyleSheet"> </head> <body> This examples uses the <b>new include features, introduced in version 1.7.2</b> and shows how it all works with autoBraces-OFF. <br><br> The enhanced includes work the following way:<br> The tag <b>\{%include include.tpl%\}</b> includes the given file, which is searched for in the templateDir first and in the include path second. The included file includes another file again, you can nest them as deep as you want!<br> NOTE: Recursive nesting will cause a warning!<br> <br> The autoBraces-OFF are used here and we are using macros <b>\{%include include.mcr%\}</b>. Since autoBraces is OFF we need a new macro tag to be introduced: it is the <b>\{%endmacro%\}</b> this is needed to tell the end of a macro, since autoBraces is not on, you need to tell the end of a macro manually. <br><br><br> --------------------------- <br><br> {%include include.tpl%} {%include_text()%} <br> ---------------------------- <br><br> just to show the if and foreach constructs, well you know them from PHP those are the <b>if():</b> and <b>endif</b> and alikes. <br> {if(sizeof($nums)>1):} {foreach($nums as $aNum):} {$aNum} <br> {endforeach} {endif} {foreach($unknown as $xxx):} {$xxx} <br> {endforeach} </body> </html> Index: pear/HTML_Template_Xipe/docs/includes/tmp/.htaccess +++ pear/HTML_Template_Xipe/docs/includes/tmp/.htaccess Options -Indexes Index: pear/HTML_Template_Xipe/docs/fullFeatured/index.php +++ pear/HTML_Template_Xipe/docs/fullFeatured/index.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // $Id: index.php,v 1.1 2003/02/10 22:19:08 cain Exp $ //ini_set('include_path',realpath(dirname(__FILE__).'/../../../../../').':'.realpath(dirname(__FILE__).'/../../../../../../includes').':'.ini_get('include_path')); //ini_set('error_reporting',E_ALL); // // make template class instance // require_once('HTML/Template/Xipe.php'); $options = array( 'templateDir' => dirname(__FILE__) //,'debug'=>true //,'forceCompile'=>true ); $tpl = new HTML_Template_Xipe($options); // // apply translating filters to the template // // this is in PEAR, get the newest version from the cvs // for more info see: http://www.php.net/anoncvs.php // source is at: http://cvs.php.net/cvs.php/pear/I18N require_once('I18N/Messages/Translate.php'); require_once('HTML/Template/Xipe/Filter/Translate.php'); $DB_DSN = 'mysql://root@localhost/test'; $translator = new I18N_Messages_Translate($DB_DSN,array('tablePrefix'=>'translate_')); function translateAndPrint( $string ) { global $translator,$lang; $translated = $translator->simpleTranslate($string,$lang); // only translate exact matches echo $translated; } if (@$_REQUEST['lang']) { $lang = $_REQUEST['lang']; } else { $lang = 'en'; } $tpl->setOption('locale',$lang); $tpl->registerPostfilter(array(&$translator,'translateMarkUpString'), $lang ); // this filter translates PHP-generated text // it simply does out of < ? =$text ? > this < ? =translateAndPrint($text) ? > // but only within the $translator->possibleMarkUpDelimiters, so not every // < ?= is translated !!! since that is not wanted anyway, // i.e. think of "<td colspan={$colspan}>" - doesnt need translation $translateFilter = new HTML_Template_Xipe_Filter_Translate($tpl->getOptions()); // this filter will only translate PHP-variables that start with 'T_', i.e. $T_foo // but not $foo as the method above would $tpl->registerPostfilter( array(&$translateFilter,'translateMarkedOnly'), array('translateAndPrint','T_') ); // // fill variables used in the template // no assign-method necessary // $repeatValue = 3; $trimValue = 'Hi guys, how is it going?'; $loop = array('one','two','three'); $url = 'http://www.kriesing.de/showsource.php?domain=wolfram.kriesing.de&file=/libs/php/SimpleTemplate/examples/'; $viewSourceCodeUrl = $url.'fullFeatured/index.php'; $viewTemplateCodeUrl = $url.'fullFeatured/index.tpl'; $viewCompiledTemplate = $url.'fullFeatured/tmp/index.tpl.en.php'; $viewCompiledTemplateDe = $url.'fullFeatured/tmp/index.tpl.de.php'; $viewTemplateLog = $url.'fullFeatured/tmp/index.tpl.log'; $viewDbFile = $url.'translate.sql'; $url = 'http://www.kriesing.de/showsource.php?domain=wolfram.kriesing.de&file=/libs/php/SimpleTemplate/'; $viewClassCodeUrl = $url.'Engine.php'; $viewFilterCodeUrl = $url.'Filter/Basic.php'; $viewTagLibCodeUrl = $url.'Filter/TagLib.php'; $languages = array('german','english'); // // show the template // $tpl->compile('index.tpl'); include($tpl->getCompiledTemplate()); ?> Index: pear/HTML_Template_Xipe/docs/fullFeatured/index.tpl +++ pear/HTML_Template_Xipe/docs/fullFeatured/index.tpl <html> <head> <title>Example - HTML_Template_Xipe</title> <link href="../style.css" type="text/css" rel="StyleSheet"> </head> <style> td.comment \{ background-color:#DDDDFF; \} </style> <body> <br> here additionally used Features:<br> <li>translate (i.e. into <a href="index.php?lang=de">german</a>, <a href="index.php?lang=en">english</a>)</li> <li>translate does by the way also convert everything to proper HTML if you want to, but you can maintain it without that in the DB</li> <li>all filters, that optimize the HTML page and cut down the page size, look at the HTML-code and you will see, this really has an effect on bigger sites</li> <li>used filters are: removeHtmlComments, removeCStyleComments, addIfBeforeForeach, trimLines, optimizeHtmlCode</li> <li>used TagLib-tags: includeFile, block, trim, repeat</li> <br><br> <a href="{$viewSourceCodeUrl}">look at the code</a><br> <a href="{$viewTemplateCodeUrl}">and the template</a><br> <a href="{$viewCompiledTemplate}">and the compiled template</a><br> <a href="{$viewCompiledTemplateDe}">and the german compiled template</a><br> <a href="{$viewTemplateLog}">template log file</a><br> <a href="{$viewDbFile}">the DB file, for the translation</a><br> <br><br> available langauges: {foreach($languages as $aLang)} <br> {$aLang} = {$T_aLang} <br><br> <table> <tr> <td colspan="4" class="comment"> <h1>Standard</h1> Actually I wanted a template engine which doesnt do much more than releiving me from the annoying <?php - tags in the HTML code and i didnt want any overhead such as assign-methods, to declare a variable which can be used in the template. I simply wanted to have all the variables available in the template that are also available in the php code. Because with other template engines, I had come across the problem very often, that i only wanted to print out a variable like $HTTP_HOST but had to assign it first to another variable which would then be available in the template, this seems to compilcated to me.<br> And since i didnt find any template engine which did all this for me i had to write this one :-)<br> Furthermore i didnt want to learn any new language which simply is less flexible than php, i wanted to be able to use php-features inside the code too, but without some of it's limitations and with the possiblity to add more features (see the TagLib). Therefore i implemented some things that make it much easier to use php inside a template. Still designers dont have to learn much more than 'if' and 'foreach' to create standard pages.<br> The simplifications are:<br> - no php-tags anymore, only a customizable character/string, such as '\{' and '\}'<br> - auto block building using the given indention, which also makes the code much better readable<br> - auto print out, by detecting '\{$' (where '\{' is the beginDelimiter ) and converting it into '<?='<br> <br> <h2>Basic Rules</h2> <h3>By default</h3> <beginDelimiter> is '\{', and<br> the <endDelimiter> is '\}', but since it is customizable i am using the 'long-form'.<br><br> Syntax: <code><beginDelimiter>content<endDelimiter></code><br> The above term is normally simple translated into: <?php content ?><br> An Exception is the following case<br> <h3>To print out directly simply use</h3> Syntax: <code><beginDelimiter>$varName<endDelimiter></code><br> as soon as a '$' sign is found behind the 'beginDelimiter' it is converted to <?=$varName ?><br> where $varName can also be:<br> - $object->property<br> - $object->method($someotherVar)<br> - $object->method($objectY->methodX())<br> <h3>To assign a varibale you can do the following:</h3> Syntax: <code><beginDelimiter> $varName=0<endDelimiter></code><br> Note the space before the '$', this simple makes $varName not being printed, it converts it to <php $varName=0 ?><br> <h3>To build a block, which in php would be done using '\{' and '\}'</h3> Syntax:<br> <code> <beginDelimiter>if or foreach<endDelimiter><br> some text, or html<br> <beginDelimiter>or processed code<endDelimiter><br> <beginDelimiter>else<endDelimiter><br> some other text, or other html<br> <beginDelimiter>or other processed code<endDelimiter><br> </code><br> Simply indent the code, that shall be in the block, the braces are automatically set around it.<br> The code above will become:<br> <code> <?php if or foreach \{?><br> some text, or html<br> <?php or processed code ?><br> <?php \} else \{ ?><br> some other text, or other html<br> <?php or other processed code ?><br> <?php \} ?><br> </code><br> <br> <h2>To get it running</h2> 1. Download the SimpleTemplate classes from <a href="http://sourceforge.net/project/showfiles.php?group_id=46064">sourceforge.net/projects/simpletpl</a>.<br> 2. Be sure to have the PEAR installed (which is default in a php-installation)!<br> 3. Put the SimpleTemplate-directory in your include path (just as the PEAR should be). You can do this either by modifiying your php.ini and add the path to 'include_path'. Or add this piece of code <code>ini_set('include_path','/complete/path/to/where/SimpleTemplate-dir/is');</code> <br> 4. And then simply include this code. <br><br> <code> require_once('SimpleTemplate/Engine.php');<br> <br> $options = array(<br> 'templateDir' => $DOCUMENT_ROOT.'/path/to/where/the/tempaltes/are',<br> 'compileDir' => $DOCUMENT_ROOT.'/path/to/a/tmp/dir'); // all compiled tpl's go here<br> or even shorter<br> 'compileDir' => 'tmp'); // now the compileDir is '<templateDir>/tmp'<br> <br> $tpl = new SimpleTemplate_Engine($options);<br> </code> <h2>Basic Filters</h2> If you are instanciating the template class it has since version 1.5 by default the 'filterLevel' set to 10 (in the options), which means that all filters that are normally needed are turned on. You can set it to 0 to turn off all filters. <br> The default filters are:<br> Basic-filters<br> - removeHtmlComments, removeCStyleComments, addIfBeforeForeach, removeEmptyLines, trimLines, optimizeHtmlCode<br> TagLib-filters<br> - includeFile, block, trimByWords, trim, repeat, applyHtmlEntites<br> <br> To manually add an additional or any custom filter simply make an instance of the filter class and register the filter as shown in the following. <br> <code> require_once('SimpleTemplate/Filter/Basic.php');<br> <br> // NOTE: since version 1.5 you should use '$tpl->getOptions()' to get the options<br> $tplFilter = new SimpleTemplate_Filter_Basic($tpl->getOptions());<br> </code> <h3>Pre-Filters</h3> Remove HTML comments and to optimize the HTML that will be delivered to the client.<br> <code> $tpl->registerPrefilter(array(&$tplFilter,'removeHtmlComments'));<br> </code> <br> Remove C-comments and to optimize JavaScript that will be delivered to the client.<br> <code> $tpl->registerPrefilter(array(&$tplFilter,'removeCStyleComments'));<br> </code> <br> Add an 'if' before every 'foreach' to prevent warnings when the variable shall be looped.<br> This has a positive side effect, you can use an 'else' on an 'foreach' since an 'if' preceeds it, see examples.<br> <code> // this filter makes the foreach-blocks conditional, so they are only shown if they contain data, see api-doc<br> $tpl->registerPrefilter(array(&$tplFilter,'addIfBeforeForeach')); <br> </code> <h3>Post-Filters</h3> Remove spaces at the beginning and at the end of each line, to cut down the size of the file that needs to be delivered to the client.<br> <code> $tpl->registerPostfilter(array(&$tplFilter,'trimLines'));<br> </code> <br> Optimize the HTML code, remove unnecesary spaces etc. also to shrink the code size.<br> <code> $tpl->registerPostfilter(array(&$tplFilter,'optimizeHtmlCode'));<br> </code> <br> Applies the function 'html_entities' to every variable that is printed from the template.<br> This converts everything to proper HTML.<br> NOTE: It might not be the wish to convert everything to HTML, stuff like $HTTP_HOST, $DOCUMENT_ROOT are sometimes needed to be printed out as they are. Then look at the TagLib function 'applyHtmlEntites'.<br> <code> $tpl->registerPostfilter(array(&$tplFilter,'applyHtmlEntites'));<br> </code> </td> </tr> </table> <h3>pre-defined variables, and their content</h3> <code> $repeatValue = {$repeatValue}<br> $trimValue = '{$trimValue}'<br> $loop = {print_r($loop)}<br> <br> <b>The Template-instance options</b><br> {foreach($tpl->getOptions() as $key=>$aOption)} $tpl->getOption('{$key}') => {if(is_array($aOption))} {print_r($aOption)} {else} {$aOption} <br> </code> <br> <h3>Examples</h3> <table> <tr> <td>example for</td> <td>code</td> <td>code in use</td> <td>comment</td> </tr> <!-- | | standard examples | +--> <tr> <td rowspan="7">standard template language</td> <td><code>\{$trimValue\}</code></td> <td> {$trimValue} </td> <td> - simply <font>display</font> of a variable's content </td> </tr> <tr> <td><code>\{$tpl->getOption('locale')\}</code></td> <td> {$tpl->getOption('locale')} </td> <td> - simply <font>display any kind</font> of variables<br> - <font>just as you do in PHP</font> </td> </tr> <tr> <td><code> <b><br> \{foreach($loop as $aLoop)\}<br> \{$key\} --- \{$aLoop\}<br><br> </b> <!-- end of foreach block,<br> because of missing indention --><br> and here goes standard html again </code></td> <td> <b> {foreach($loop as $key=>$aLoop)} {$key} => {$aLoop}<br> </b> </td> <td> - this what most template engines call <font>blocks</font>, <br> simply use the foreach as you are used to<br> - the <font>indention</font> makes it easy to leave out the<br>block delimiters, ' \{ ' and ' \} ' </td> </tr> <tr> <td nowrap><code> \{foreach($tpl->getOption('delimiter') as $key=>$value)\}<br> \{$key\} => \{$value\}<br><br> </code></td> <td> {foreach($tpl->getOption('delimiter') as $key=>$value)} {$key} => {$value}<br> </td> <td> - simple loop, as you would do in PHP </td> </tr> <tr> <td nowrap><code> \{foreach($tpl->getOptions() as $key=>$aOption)\}<br> \{$key\} => <b>\{%trim $aOption 10 "..."%\}<br> </b><br> </code></td> <td> {foreach($tpl->getOptions() as $key=>$aOption)} {$key} => <b>{%trim $aOption 10 "..."%} </b><br> </td> <td> - or loop through a variables content<br> <font>as you are used to in PHP</font><br> - for explaination of \{%trim ...%\} please look further down </td> </tr> <tr> <td> <code> \{foreach($emptyLoopVariable as $key=>$aLoop)\}<br> \{$key\} --- \{$aLoop\}<br><br> \{else\}<br> nothing<br><br> in:<br><br> $emptyLoopVariable<br> </code> </td> <td> {foreach($emptyLoopVariable as $key=>$aLoop)} {$key} --- {$aLoop}<br> {else} nothing<br> in:<br> $emptyLoopVariable </td> <td> - if you use the <font>filter 'addIfBeforeForeach'</font><br> an 'foreach' also has an 'else'<br> - the <font>block can be as big as you like</font> it to be </td> </tr> <tr> <td><code> \{if( sizeof($loop)>3 )\}<br> \{foreach($loop as $key=>$aLoop)\}<br> \{$key\} --- \{$aLoop\}<br><br> \{else\}<br> $loop doesnt have more than 3 values </code></td> <td> {if( sizeof($loop)>3 )} {foreach($loop as $key=>$aLoop)} {$key} --- {$aLoop}<br> {else} $loop doesnt have more than 3 values </td> <td> - or any other combination of <font>nesting</font>,<br> just as endless as PHP allows it </td> </tr> <!-- | | examples for " \{ % % \} " | +--> <tr> <td colspan="4" class="comment"> <h1>TagLib</h1> All extra-functionality that extends the template-engine is collected in the "TagLib".<br> All TagLib tags are surrounded by the delimiters and additionally a '%'-sign inside at the beginning and at the end.<br><br> Syntax: <beginDelimiter>%content%<endDelimiter><br><br> <b>to activate the TagLib functionality insert the following code in your php file</b><br><br> <code> require_once('SimpleTemplate/Filter/TagLib.php');<br><br> // $tpl is the instance of SimpleTemplate_Engine,<br> // passing this parameter passes all the options to the created instance<br> $tagLib = new SimpleTemplate_Filter_TagLib($tpl->getOptions());<br><br> </code> </td> </tr> <tr> <td rowspan="2">TagLib, applyHtmlEntites</td> <td colspan="3" class="comment"> <b>to activate this functionality</b><br><br> <code> $tpl->registerPrefilter(array(&$tagLib,'applyHtmlEntites'));<br> </code> </td> </tr> <tr> <td><code>\{%$trimValue%\}</code></td> <td> {%$trimValue%} </td> <td> - simply converts all not-HTML characters to proper HTML<br> </td> </tr> <!-- | | examples for "repeat" | +--> <tr> <td rowspan="6">TagLib, repeat</td> <td colspan="3" class="comment"> <b>to activate this functionality</b><br><br> <code> $tpl->registerPrefilter(array(&$tagLib,'repeat'));<br> </code> </td> </tr> <tr> <td><code>\{%repeat $repeatValue times%\}<br> -<br></code></td> <td> {%repeat $repeatValue times%} - </td> <td> - a very <font>readable</font> way to use this, good for designer, who create those pages<br> - watch out to use proper indention for the block that shall be repeated </td> </tr> <tr> <td><code>\{%repeat $repeatValue%\}<br> -<br></code></td> <td> {%repeat $repeatValue%} - </td> <td> - or simply that<br> </td> </tr> <tr> <td><code>\{%repeat $repeatValue times with $y%\}<br> - \{$y\}<br></code></td> <td> {%repeat $repeatValue times with $y%} - {$y} </td> <td> - a <font>counter variable</font> can be used too<br> - the value is shown on every loop run, here it is named $y<br> - NOTE: the string 'times with' can be anything you like, it serves readability </td> </tr> <tr> <td><code>\{%repeat $repeatValue $counterVariable%\}<br> - \{$counterVariable*2\}<br></code></td> <td> {%repeat $repeatValue $counterVariable%} - {$counterVariable*2} </td> <td> - or as simple as that<br> - and give the counter variable a name you like to </td> </tr> <tr> <td nowrap><code>\{%repeat $repeatValue many times, using $y%\}<br> - \{$y*3\}<br></code></td> <td> {%repeat $repeatValue many times, using $y%} - {$y*3} </td> <td> - or as hard core extrem as you like<br> - write anything there, so others understand what is meant </td> </tr> <!-- | | examples for "trim" | +--> <tr> <td rowspan="5">TagLib, trim</td> <td colspan="3" class="comment"> <b>to activate this functionality</b><br><br> <code> $tpl->registerPrefilter(array(&$tagLib,'trim'));<br> </code> </td> </tr> <tr> <td><code>\{%trim $trimValue after 8 characters and add "..."%\}</code></td> <td> {%trim $trimValue after 8 characters and add "..."%} </td> <td> - readable version </td> </tr> <tr> <td><code>\{%trim $trimValue 12 "..."%\}</code></td> <td> {%trim $trimValue 12 "..."%} </td> <td> - or as simply as this </td> </tr> <tr> <td><code>\{%trim $trimValue 11%\}</code></td> <td> {%trim $trimValue 11%} </td> <td> - or even simpler, without adding anything </td> </tr> <tr> <td><code>\{%trim $trimValue 2 "...$trimValue..."%\}</code></td> <td> {%trim $trimValue 2 "...$trimValue..."%} </td> <td> - or kinda recursive<br> </td> </tr> <!-- | | examples for "trimByWords" | +--> <tr> <td rowspan="2">TagLib, trimByWords</td> <td colspan="3" class="comment"> <b>to activate this functionality</b><br><br> <code> $tpl->registerPrefilter(array(&$tagLib,'trimByWords'));<br> </code> </td> </tr> <tr> <td><code>\{%trim $trimValue by words after 5 characters and add "..."%\}</code></td> <td> {%trim $trimValue by words after 5 characters and add "..."%} </td> <td> - trims a string but only at spaces, if there is no space at the given offset, it goes back in the string, so that the max-length is not longer than the given one </td> </tr> <!-- | | examples for "include" | +--> <tr> <td rowspan="2">TagLib, include</td> <td colspan="3" class="comment"> <b>to activate this functionality</b><br><br> <code> $tpl->registerPrefilter(array(&$tagLib,'includeFile'));<br> </code> </td> </tr> <tr> <td><code>\{%include blocks/common.blocks%\}</code></td> <td> </td> <td> - includes the file 'blocks/common.blocks'<br> - this file can contain any kind of blocks,<br> which you can display using the \{%copy block ...%\} tag </td> </tr> <!-- | | examples for "block" | +--> <tr> <td rowspan="3">TagLib, block</td> <td colspan="3" class="comment"> <b>to activate this functionality</b><br><br> <code> $tpl->registerPrefilter(array(&$tagLib,'block'));<br> </code> </td> </tr> <tr> <td><code> \{ %block showThis%\}<br> block content \{$trimValue\}<br> \{%/block%\}<br> </code> </td> {%block showThis%} block content<br> {$trimValue} {%/block%} <td> </td> <td> - define a block and its content here<br> - this block will simply be copied<br> where you write \{%copy block showThis%\} </td> </tr> <tr> <td><code> \{%copy block showThis here%\}<br> </code> </td> <td> {%copy block showThis %} </td> <td> - copy the block here and replace the variables normally<br> </td> </tr> </table> <br><br> </body> </html> Index: pear/HTML_Template_Xipe/docs/fullFeatured/tmp/.htaccess +++ pear/HTML_Template_Xipe/docs/fullFeatured/tmp/.htaccess Options -Indexes
Index: pear/HTML_Template_Xipe/docs/includes/include.mcr +++ pear/HTML_Template_Xipe/docs/includes/include.mcr <!--// // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // $Id: include.mcr,v 1.1 2003/02/10 22:19:08 cain Exp $ //--> {%include include1.mcr%} {%macro include_text()%} <br><br> this is text from the macro \{%include_text()%\} which is in the file <b>include.mcr</b> <br> {%include1_text()%} {%endmacro%} Index: pear/HTML_Template_Xipe/docs/includes/include.tpl +++ pear/HTML_Template_Xipe/docs/includes/include.tpl <!--// // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // $Id: include.tpl,v 1.1 2003/02/10 22:19:08 cain Exp $ //--> <br> i am a text from include.tpl <br> {%include include1.tpl%} Index: pear/HTML_Template_Xipe/docs/includes/include1.mcr +++ pear/HTML_Template_Xipe/docs/includes/include1.mcr <!--// // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // $Id: include1.mcr,v 1.1 2003/02/10 22:19:08 cain Exp $ //--> {%macro include1_text()%} <br><br> this is text from the macro \{%include1_text()%\} which is in the file <b>include1.mcr</b> <br> {%endmacro%} Index: pear/HTML_Template_Xipe/docs/includes/include1.tpl +++ pear/HTML_Template_Xipe/docs/includes/include1.tpl <!--// // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // $Id: include1.tpl,v 1.1 2003/02/10 22:19:08 cain Exp $ //--> <br> i am a text from include1.tpl <br> Index: pear/HTML_Template_Xipe/docs/includes/index.php +++ pear/HTML_Template_Xipe/docs/includes/index.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // $Id: index.php,v 1.1 2003/02/10 22:19:08 cain Exp $ ini_set('include_path',realpath(dirname(__FILE__).'/../../../../../').':'.realpath(dirname(__FILE__).'/../../../../../../includes').':'.ini_get('include_path')); ini_set('error_reporting',E_ALL); // // include the files needed // require_once('HTML/Template/Xipe.php'); require_once('HTML/Template/Xipe/Filter/Basic.php'); // // make template class instance // $options = array( 'templateDir' => dirname(__FILE__) ,'compileDir' => 'tmp' // use the compile dir 'tmp' under the template dir ,'autoBraces' => false ,'forceCompile'=>true //,'filterLevel'=>9 ); $tpl = new HTML_Template_Xipe($options); // fill some vars $nums = array('one','two','three'); // // show the template // $tpl->compile('index.tpl'); include($tpl->getCompiledTemplate()); ?> Index: pear/HTML_Template_Xipe/docs/includes/index.tpl +++ pear/HTML_Template_Xipe/docs/includes/index.tpl <!--// // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // $Id: index.tpl,v 1.1 2003/02/10 22:19:08 cain Exp $ //--> {%include include.mcr%} <html> <head> <title>Example - HTML_Template_Xipe - includes</title> <link href="../style.css" type="text/css" rel="StyleSheet"> </head> <body> This examples uses the <b>new include features, introduced in version 1.7.2</b> and shows how it all works with autoBraces-OFF. <br><br> The enhanced includes work the following way:<br> The tag <b>\{%include include.tpl%\}</b> includes the given file, which is searched for in the templateDir first and in the include path second. The included file includes another file again, you can nest them as deep as you want!<br> NOTE: Recursive nesting will cause a warning!<br> <br> The autoBraces-OFF are used here and we are using macros <b>\{%include include.mcr%\}</b>. Since autoBraces is OFF we need a new macro tag to be introduced: it is the <b>\{%endmacro%\}</b> this is needed to tell the end of a macro, since autoBraces is not on, you need to tell the end of a macro manually. <br><br><br> --------------------------- <br><br> {%include include.tpl%} {%include_text()%} <br> ---------------------------- <br><br> just to show the if and foreach constructs, well you know them from PHP those are the <b>if():</b> and <b>endif</b> and alikes. <br> {if(sizeof($nums)>1):} {foreach($nums as $aNum):} {$aNum} <br> {endforeach} {endif} {foreach($unknown as $xxx):} {$xxx} <br> {endforeach} </body> </html> Index: pear/HTML_Template_Xipe/docs/includes/tmp/.htaccess +++ pear/HTML_Template_Xipe/docs/includes/tmp/.htaccess Options -Indexes Index: pear/HTML_Template_Xipe/docs/fullFeatured/index.php +++ pear/HTML_Template_Xipe/docs/fullFeatured/index.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // $Id: index.php,v 1.1 2003/02/10 22:19:08 cain Exp $ //ini_set('include_path',realpath(dirname(__FILE__).'/../../../../../').':'.realpath(dirname(__FILE__).'/../../../../../../includes').':'.ini_get('include_path')); //ini_set('error_reporting',E_ALL); // // make template class instance // require_once('HTML/Template/Xipe.php'); $options = array( 'templateDir' => dirname(__FILE__) //,'debug'=>true //,'forceCompile'=>true ); $tpl = new HTML_Template_Xipe($options); // // apply translating filters to the template // // this is in PEAR, get the newest version from the cvs // for more info see: http://www.php.net/anoncvs.php // source is at: http://cvs.php.net/cvs.php/pear/I18N require_once('I18N/Messages/Translate.php'); require_once('HTML/Template/Xipe/Filter/Translate.php'); $DB_DSN = 'mysql://root@localhost/test'; $translator = new I18N_Messages_Translate($DB_DSN,array('tablePrefix'=>'translate_')); function translateAndPrint( $string ) { global $translator,$lang; $translated = $translator->simpleTranslate($string,$lang); // only translate exact matches echo $translated; } if (@$_REQUEST['lang']) { $lang = $_REQUEST['lang']; } else { $lang = 'en'; } $tpl->setOption('locale',$lang); $tpl->registerPostfilter(array(&$translator,'translateMarkUpString'), $lang ); // this filter translates PHP-generated text // it simply does out of < ? =$text ? > this < ? =translateAndPrint($text) ? > // but only within the $translator->possibleMarkUpDelimiters, so not every // < ?= is translated !!! since that is not wanted anyway, // i.e. think of "<td colspan={$colspan}>" - doesnt need translation $translateFilter = new HTML_Template_Xipe_Filter_Translate($tpl->getOptions()); // this filter will only translate PHP-variables that start with 'T_', i.e. $T_foo // but not $foo as the method above would $tpl->registerPostfilter( array(&$translateFilter,'translateMarkedOnly'), array('translateAndPrint','T_') ); // // fill variables used in the template // no assign-method necessary // $repeatValue = 3; $trimValue = 'Hi guys, how is it going?'; $loop = array('one','two','three'); $url = 'http://www.kriesing.de/showsource.php?domain=wolfram.kriesing.de&file=/libs/php/SimpleTemplate/examples/'; $viewSourceCodeUrl = $url.'fullFeatured/index.php'; $viewTemplateCodeUrl = $url.'fullFeatured/index.tpl'; $viewCompiledTemplate = $url.'fullFeatured/tmp/index.tpl.en.php'; $viewCompiledTemplateDe = $url.'fullFeatured/tmp/index.tpl.de.php'; $viewTemplateLog = $url.'fullFeatured/tmp/index.tpl.log'; $viewDbFile = $url.'translate.sql'; $url = 'http://www.kriesing.de/showsource.php?domain=wolfram.kriesing.de&file=/libs/php/SimpleTemplate/'; $viewClassCodeUrl = $url.'Engine.php'; $viewFilterCodeUrl = $url.'Filter/Basic.php'; $viewTagLibCodeUrl = $url.'Filter/TagLib.php'; $languages = array('german','english'); // // show the template // $tpl->compile('index.tpl'); include($tpl->getCompiledTemplate()); ?> Index: pear/HTML_Template_Xipe/docs/fullFeatured/index.tpl +++ pear/HTML_Template_Xipe/docs/fullFeatured/index.tpl <html> <head> <title>Example - HTML_Template_Xipe</title> <link href="../style.css" type="text/css" rel="StyleSheet"> </head> <style> td.comment \{ background-color:#DDDDFF; \} </style> <body> <br> here additionally used Features:<br> <li>translate (i.e. into <a href="index.php?lang=de">german</a>, <a href="index.php?lang=en">english</a>)</li> <li>translate does by the way also convert everything to proper HTML if you want to, but you can maintain it without that in the DB</li> <li>all filters, that optimize the HTML page and cut down the page size, look at the HTML-code and you will see, this really has an effect on bigger sites</li> <li>used filters are: removeHtmlComments, removeCStyleComments, addIfBeforeForeach, trimLines, optimizeHtmlCode</li> <li>used TagLib-tags: includeFile, block, trim, repeat</li> <br><br> <a href="{$viewSourceCodeUrl}">look at the code</a><br> <a href="{$viewTemplateCodeUrl}">and the template</a><br> <a href="{$viewCompiledTemplate}">and the compiled template</a><br> <a href="{$viewCompiledTemplateDe}">and the german compiled template</a><br> <a href="{$viewTemplateLog}">template log file</a><br> <a href="{$viewDbFile}">the DB file, for the translation</a><br> <br><br> available langauges: {foreach($languages as $aLang)} <br> {$aLang} = {$T_aLang} <br><br> <table> <tr> <td colspan="4" class="comment"> <h1>Standard</h1> Actually I wanted a template engine which doesnt do much more than releiving me from the annoying <?php - tags in the HTML code and i didnt want any overhead such as assign-methods, to declare a variable which can be used in the template. I simply wanted to have all the variables available in the template that are also available in the php code. Because with other template engines, I had come across the problem very often, that i only wanted to print out a variable like $HTTP_HOST but had to assign it first to another variable which would then be available in the template, this seems to compilcated to me.<br> And since i didnt find any template engine which did all this for me i had to write this one :-)<br> Furthermore i didnt want to learn any new language which simply is less flexible than php, i wanted to be able to use php-features inside the code too, but without some of it's limitations and with the possiblity to add more features (see the TagLib). Therefore i implemented some things that make it much easier to use php inside a template. Still designers dont have to learn much more than 'if' and 'foreach' to create standard pages.<br> The simplifications are:<br> - no php-tags anymore, only a customizable character/string, such as '\{' and '\}'<br> - auto block building using the given indention, which also makes the code much better readable<br> - auto print out, by detecting '\{$' (where '\{' is the beginDelimiter ) and converting it into '<?='<br> <br> <h2>Basic Rules</h2> <h3>By default</h3> <beginDelimiter> is '\{', and<br> the <endDelimiter> is '\}', but since it is customizable i am using the 'long-form'.<br><br> Syntax: <code><beginDelimiter>content<endDelimiter></code><br> The above term is normally simple translated into: <?php content ?><br> An Exception is the following case<br> <h3>To print out directly simply use</h3> Syntax: <code><beginDelimiter>$varName<endDelimiter></code><br> as soon as a '$' sign is found behind the 'beginDelimiter' it is converted to <?=$varName ?><br> where $varName can also be:<br> - $object->property<br> - $object->method($someotherVar)<br> - $object->method($objectY->methodX())<br> <h3>To assign a varibale you can do the following:</h3> Syntax: <code><beginDelimiter> $varName=0<endDelimiter></code><br> Note the space before the '$', this simple makes $varName not being printed, it converts it to <php $varName=0 ?><br> <h3>To build a block, which in php would be done using '\{' and '\}'</h3> Syntax:<br> <code> <beginDelimiter>if or foreach<endDelimiter><br> some text, or html<br> <beginDelimiter>or processed code<endDelimiter><br> <beginDelimiter>else<endDelimiter><br> some other text, or other html<br> <beginDelimiter>or other processed code<endDelimiter><br> </code><br> Simply indent the code, that shall be in the block, the braces are automatically set around it.<br> The code above will become:<br> <code> <?php if or foreach \{?><br> some text, or html<br> <?php or processed code ?><br> <?php \} else \{ ?><br> some other text, or other html<br> <?php or other processed code ?><br> <?php \} ?><br> </code><br> <br> <h2>To get it running</h2> 1. Download the SimpleTemplate classes from <a href="http://sourceforge.net/project/showfiles.php?group_id=46064">sourceforge.net/projects/simpletpl</a>.<br> 2. Be sure to have the PEAR installed (which is default in a php-installation)!<br> 3. Put the SimpleTemplate-directory in your include path (just as the PEAR should be). You can do this either by modifiying your php.ini and add the path to 'include_path'. Or add this piece of code <code>ini_set('include_path','/complete/path/to/where/SimpleTemplate-dir/is');</code> <br> 4. And then simply include this code. <br><br> <code> require_once('SimpleTemplate/Engine.php');<br> <br> $options = array(<br> 'templateDir' => $DOCUMENT_ROOT.'/path/to/where/the/tempaltes/are',<br> 'compileDir' => $DOCUMENT_ROOT.'/path/to/a/tmp/dir'); // all compiled tpl's go here<br> or even shorter<br> 'compileDir' => 'tmp'); // now the compileDir is '<templateDir>/tmp'<br> <br> $tpl = new SimpleTemplate_Engine($options);<br> </code> <h2>Basic Filters</h2> If you are instanciating the template class it has since version 1.5 by default the 'filterLevel' set to 10 (in the options), which means that all filters that are normally needed are turned on. You can set it to 0 to turn off all filters. <br> The default filters are:<br> Basic-filters<br> - removeHtmlComments, removeCStyleComments, addIfBeforeForeach, removeEmptyLines, trimLines, optimizeHtmlCode<br> TagLib-filters<br> - includeFile, block, trimByWords, trim, repeat, applyHtmlEntites<br> <br> To manually add an additional or any custom filter simply make an instance of the filter class and register the filter as shown in the following. <br> <code> require_once('SimpleTemplate/Filter/Basic.php');<br> <br> // NOTE: since version 1.5 you should use '$tpl->getOptions()' to get the options<br> $tplFilter = new SimpleTemplate_Filter_Basic($tpl->getOptions());<br> </code> <h3>Pre-Filters</h3> Remove HTML comments and to optimize the HTML that will be delivered to the client.<br> <code> $tpl->registerPrefilter(array(&$tplFilter,'removeHtmlComments'));<br> </code> <br> Remove C-comments and to optimize JavaScript that will be delivered to the client.<br> <code> $tpl->registerPrefilter(array(&$tplFilter,'removeCStyleComments'));<br> </code> <br> Add an 'if' before every 'foreach' to prevent warnings when the variable shall be looped.<br> This has a positive side effect, you can use an 'else' on an 'foreach' since an 'if' preceeds it, see examples.<br> <code> // this filter makes the foreach-blocks conditional, so they are only shown if they contain data, see api-doc<br> $tpl->registerPrefilter(array(&$tplFilter,'addIfBeforeForeach')); <br> </code> <h3>Post-Filters</h3> Remove spaces at the beginning and at the end of each line, to cut down the size of the file that needs to be delivered to the client.<br> <code> $tpl->registerPostfilter(array(&$tplFilter,'trimLines'));<br> </code> <br> Optimize the HTML code, remove unnecesary spaces etc. also to shrink the code size.<br> <code> $tpl->registerPostfilter(array(&$tplFilter,'optimizeHtmlCode'));<br> </code> <br> Applies the function 'html_entities' to every variable that is printed from the template.<br> This converts everything to proper HTML.<br> NOTE: It might not be the wish to convert everything to HTML, stuff like $HTTP_HOST, $DOCUMENT_ROOT are sometimes needed to be printed out as they are. Then look at the TagLib function 'applyHtmlEntites'.<br> <code> $tpl->registerPostfilter(array(&$tplFilter,'applyHtmlEntites'));<br> </code> </td> </tr> </table> <h3>pre-defined variables, and their content</h3> <code> $repeatValue = {$repeatValue}<br> $trimValue = '{$trimValue}'<br> $loop = {print_r($loop)}<br> <br> <b>The Template-instance options</b><br> {foreach($tpl->getOptions() as $key=>$aOption)} $tpl->getOption('{$key}') => {if(is_array($aOption))} {print_r($aOption)} {else} {$aOption} <br> </code> <br> <h3>Examples</h3> <table> <tr> <td>example for</td> <td>code</td> <td>code in use</td> <td>comment</td> </tr> <!-- | | standard examples | +--> <tr> <td rowspan="7">standard template language</td> <td><code>\{$trimValue\}</code></td> <td> {$trimValue} </td> <td> - simply <font>display</font> of a variable's content </td> </tr> <tr> <td><code>\{$tpl->getOption('locale')\}</code></td> <td> {$tpl->getOption('locale')} </td> <td> - simply <font>display any kind</font> of variables<br> - <font>just as you do in PHP</font> </td> </tr> <tr> <td><code> <b><br> \{foreach($loop as $aLoop)\}<br> \{$key\} --- \{$aLoop\}<br><br> </b> <!-- end of foreach block,<br> because of missing indention --><br> and here goes standard html again </code></td> <td> <b> {foreach($loop as $key=>$aLoop)} {$key} => {$aLoop}<br> </b> </td> <td> - this what most template engines call <font>blocks</font>, <br> simply use the foreach as you are used to<br> - the <font>indention</font> makes it easy to leave out the<br>block delimiters, ' \{ ' and ' \} ' </td> </tr> <tr> <td nowrap><code> \{foreach($tpl->getOption('delimiter') as $key=>$value)\}<br> \{$key\} => \{$value\}<br><br> </code></td> <td> {foreach($tpl->getOption('delimiter') as $key=>$value)} {$key} => {$value}<br> </td> <td> - simple loop, as you would do in PHP </td> </tr> <tr> <td nowrap><code> \{foreach($tpl->getOptions() as $key=>$aOption)\}<br> \{$key\} => <b>\{%trim $aOption 10 "..."%\}<br> </b><br> </code></td> <td> {foreach($tpl->getOptions() as $key=>$aOption)} {$key} => <b>{%trim $aOption 10 "..."%} </b><br> </td> <td> - or loop through a variables content<br> <font>as you are used to in PHP</font><br> - for explaination of \{%trim ...%\} please look further down </td> </tr> <tr> <td> <code> \{foreach($emptyLoopVariable as $key=>$aLoop)\}<br> \{$key\} --- \{$aLoop\}<br><br> \{else\}<br> nothing<br><br> in:<br><br> $emptyLoopVariable<br> </code> </td> <td> {foreach($emptyLoopVariable as $key=>$aLoop)} {$key} --- {$aLoop}<br> {else} nothing<br> in:<br> $emptyLoopVariable </td> <td> - if you use the <font>filter 'addIfBeforeForeach'</font><br> an 'foreach' also has an 'else'<br> - the <font>block can be as big as you like</font> it to be </td> </tr> <tr> <td><code> \{if( sizeof($loop)>3 )\}<br> \{foreach($loop as $key=>$aLoop)\}<br> \{$key\} --- \{$aLoop\}<br><br> \{else\}<br> $loop doesnt have more than 3 values </code></td> <td> {if( sizeof($loop)>3 )} {foreach($loop as $key=>$aLoop)} {$key} --- {$aLoop}<br> {else} $loop doesnt have more than 3 values </td> <td> - or any other combination of <font>nesting</font>,<br> just as endless as PHP allows it </td> </tr> <!-- | | examples for " \{ % % \} " | +--> <tr> <td colspan="4" class="comment"> <h1>TagLib</h1> All extra-functionality that extends the template-engine is collected in the "TagLib".<br> All TagLib tags are surrounded by the delimiters and additionally a '%'-sign inside at the beginning and at the end.<br><br> Syntax: <beginDelimiter>%content%<endDelimiter><br><br> <b>to activate the TagLib functionality insert the following code in your php file</b><br><br> <code> require_once('SimpleTemplate/Filter/TagLib.php');<br><br> // $tpl is the instance of SimpleTemplate_Engine,<br> // passing this parameter passes all the options to the created instance<br> $tagLib = new SimpleTemplate_Filter_TagLib($tpl->getOptions());<br><br> </code> </td> </tr> <tr> <td rowspan="2">TagLib, applyHtmlEntites</td> <td colspan="3" class="comment"> <b>to activate this functionality</b><br><br> <code> $tpl->registerPrefilter(array(&$tagLib,'applyHtmlEntites'));<br> </code> </td> </tr> <tr> <td><code>\{%$trimValue%\}</code></td> <td> {%$trimValue%} </td> <td> - simply converts all not-HTML characters to proper HTML<br> </td> </tr> <!-- | | examples for "repeat" | +--> <tr> <td rowspan="6">TagLib, repeat</td> <td colspan="3" class="comment"> <b>to activate this functionality</b><br><br> <code> $tpl->registerPrefilter(array(&$tagLib,'repeat'));<br> </code> </td> </tr> <tr> <td><code>\{%repeat $repeatValue times%\}<br> -<br></code></td> <td> {%repeat $repeatValue times%} - </td> <td> - a very <font>readable</font> way to use this, good for designer, who create those pages<br> - watch out to use proper indention for the block that shall be repeated </td> </tr> <tr> <td><code>\{%repeat $repeatValue%\}<br> -<br></code></td> <td> {%repeat $repeatValue%} - </td> <td> - or simply that<br> </td> </tr> <tr> <td><code>\{%repeat $repeatValue times with $y%\}<br> - \{$y\}<br></code></td> <td> {%repeat $repeatValue times with $y%} - {$y} </td> <td> - a <font>counter variable</font> can be used too<br> - the value is shown on every loop run, here it is named $y<br> - NOTE: the string 'times with' can be anything you like, it serves readability </td> </tr> <tr> <td><code>\{%repeat $repeatValue $counterVariable%\}<br> - \{$counterVariable*2\}<br></code></td> <td> {%repeat $repeatValue $counterVariable%} - {$counterVariable*2} </td> <td> - or as simple as that<br> - and give the counter variable a name you like to </td> </tr> <tr> <td nowrap><code>\{%repeat $repeatValue many times, using $y%\}<br> - \{$y*3\}<br></code></td> <td> {%repeat $repeatValue many times, using $y%} - {$y*3} </td> <td> - or as hard core extrem as you like<br> - write anything there, so others understand what is meant </td> </tr> <!-- | | examples for "trim" | +--> <tr> <td rowspan="5">TagLib, trim</td> <td colspan="3" class="comment"> <b>to activate this functionality</b><br><br> <code> $tpl->registerPrefilter(array(&$tagLib,'trim'));<br> </code> </td> </tr> <tr> <td><code>\{%trim $trimValue after 8 characters and add "..."%\}</code></td> <td> {%trim $trimValue after 8 characters and add "..."%} </td> <td> - readable version </td> </tr> <tr> <td><code>\{%trim $trimValue 12 "..."%\}</code></td> <td> {%trim $trimValue 12 "..."%} </td> <td> - or as simply as this </td> </tr> <tr> <td><code>\{%trim $trimValue 11%\}</code></td> <td> {%trim $trimValue 11%} </td> <td> - or even simpler, without adding anything </td> </tr> <tr> <td><code>\{%trim $trimValue 2 "...$trimValue..."%\}</code></td> <td> {%trim $trimValue 2 "...$trimValue..."%} </td> <td> - or kinda recursive<br> </td> </tr> <!-- | | examples for "trimByWords" | +--> <tr> <td rowspan="2">TagLib, trimByWords</td> <td colspan="3" class="comment"> <b>to activate this functionality</b><br><br> <code> $tpl->registerPrefilter(array(&$tagLib,'trimByWords'));<br> </code> </td> </tr> <tr> <td><code>\{%trim $trimValue by words after 5 characters and add "..."%\}</code></td> <td> {%trim $trimValue by words after 5 characters and add "..."%} </td> <td> - trims a string but only at spaces, if there is no space at the given offset, it goes back in the string, so that the max-length is not longer than the given one </td> </tr> <!-- | | examples for "include" | +--> <tr> <td rowspan="2">TagLib, include</td> <td colspan="3" class="comment"> <b>to activate this functionality</b><br><br> <code> $tpl->registerPrefilter(array(&$tagLib,'includeFile'));<br> </code> </td> </tr> <tr> <td><code>\{%include blocks/common.blocks%\}</code></td> <td> </td> <td> - includes the file 'blocks/common.blocks'<br> - this file can contain any kind of blocks,<br> which you can display using the \{%copy block ...%\} tag </td> </tr> <!-- | | examples for "block" | +--> <tr> <td rowspan="3">TagLib, block</td> <td colspan="3" class="comment"> <b>to activate this functionality</b><br><br> <code> $tpl->registerPrefilter(array(&$tagLib,'block'));<br> </code> </td> </tr> <tr> <td><code> \{ %block showThis%\}<br> block content \{$trimValue\}<br> \{%/block%\}<br> </code> </td> {%block showThis%} block content<br> {$trimValue} {%/block%} <td> </td> <td> - define a block and its content here<br> - this block will simply be copied<br> where you write \{%copy block showThis%\} </td> </tr> <tr> <td><code> \{%copy block showThis here%\}<br> </code> </td> <td> {%copy block showThis %} </td> <td> - copy the block here and replace the variables normally<br> </td> </tr> </table> <br><br> </body> </html> Index: pear/HTML_Template_Xipe/docs/fullFeatured/tmp/.htaccess +++ pear/HTML_Template_Xipe/docs/fullFeatured/tmp/.htaccess Options -Indexes