Esempio n. 1
0
    // 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';
Esempio n. 2
0
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', 'verbose' => true, 'locale' => '', 'logLevel' => 1, 'filterLevel' => 0);
$tpl = new HTML_Template_Xipe($options);
//
//   make filter class instance
//   and apply filters as needed
//
$tplFilter = new HTML_Template_Xipe_Filter_Basic($tpl->getOptions());
// pre filter
$tpl->registerPrefilter(array(&$tplFilter, 'removeHtmlComments'));
$tpl->registerPrefilter(array(&$tplFilter, 'removeCStyleComments'));
$tpl->registerPrefilter(array(&$tplFilter, 'addIfBeforeForeach'));
// this filter makes the foreach-blocks conditional, so they are only shown if they contain data, see api-doc
// post filter
$tpl->registerPostfilter(array(&$tplFilter, 'trimLines'));
$tpl->registerPostfilter(array(&$tplFilter, 'optimizeHtmlCode'));
//
//   fill variables used in the template
//   no assign-method necessary
//
$advantages = array('clean HTML-code', 'ALL the power of PHP inside a template', 'a compiled template', 'easy to use (template) engine');
$dontLike = array('php-tags in your html', 'the braces: "{" and "}", since they could be replaced by proper indention', 'to learn a new template language');
$viewSourceCodeUrl = 'http://www.kriesing.de/showsource.php?domain=wolfram.kriesing.de&file=/libs/php/SimpleTemplate/examples/simple/index.php';