index.tpl
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· TPL 代码 · 共 629 行 · 第 1/2 页
TPL
629 行
<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>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?