/** * Creates a template object * * Subclasses should override this if they're not okay with using templates * of the class specified in the template_class option to PHPSTL * * @param resource string the string resource to pass to the template constructor * @param data mixed the value to set as $template->providerData * @param identified string identifier string override as in PHPSTLTemplate::__construct */ protected function createTemplate($resource, $data, $identifier = null) { $class = $this->pstl->getOption('template_class', 'PHPSTLTemplate'); $template = new $class($this, $resource, $identifier); $template->providerData = $data; return $template; }
public function initialize() { parent::initialize(); require_once "{$this->dir}/php-stl/PHPSTL.php"; require_once "{$this->dir}/FrameworkCompiler.php"; require_once "{$this->dir}/Template.php"; if ($this->hasModule('PageSystem')) { require_once "{$this->dir}/ContentPageTemplateProvider.php"; } PHPSTL::registerNamespace('urn:redtree:ui:form:v1.0', 'TemplateFormHandler', dirname(__FILE__) . '/TemplateFormHandler.php'); if ($this->hasModule('PageSystem')) { PHPSTL::registerNamespace('urn:redtree:ui:page:v1.0', 'TemplatePageHandler', dirname(__FILE__) . '/TemplatePageHandler.php'); } $this->site->addCallback('onPostConfig', array($this, 'onPostConfig')); }
/** * Returns a handler for a namspace, or throws a PHPSTLCompilerException * if we can't handle it * * @param DOMNode $node * @return PHPSTLNSHandler an instance of PHPSTLNSHandler that should handle * the given namespace */ protected function handleNamespace($namespace) { if (!isset($this->handlers)) { throw new RuntimeException('not compiling any document right now'); } if (!isset($this->handlers[$namespace])) { try { $class = PHPSTL::getNamespaceHandler($namespace); } catch (InvalidArgumentException $e) { throw new PHPSTLCompilerException($this, $e->getMessage()); } $this->handlers[$namespace] = new $class($this, $namespace); } return $this->handlers[$namespace]; }
* @param args mixed array or null * @return string * @see load, PHPSTLTemplate::render */ public function process($resource, $args = null) { $template = $this->load($resource); return $template->render($args); } } class PHPSTLNoSuchResource extends RuntimeException { private $pstl; public function getPHPSTL() { return $this->pstl; } private $resource; public function getResource() { return $this->resource; } public function __construct(PHPSTL $pstl, $resource) { $this->pstl = $pstl; $this->resource = $resource; parent::__construct("No such template {$resource}"); } } PHPSTL::registerNamespace('urn:redtree:php-stl:core:v2.0', 'PHPSTLCoreHandler', dirname(__FILE__) . '/PHPSTLCoreHandler.php');
#!/usr/bin/php <?php require "PHPSTL.php"; $pstl = new PHPSTL(array('include_path' => array('.'), 'compile_caching' => false, 'diskcache_directory' => 'template-test-cache', 'diskcache_hashed' => false, 'always_compile' => true)); // $t->getPHPSTLCompiler()->setCaching(false); // TODO test abs $coretest = $pstl->load('coretest'); print "CoreTag Test:\n"; $out = $coretest->render(); $a = explode("\n", $out); for ($i = 0; $i < count($a); ++$i) { printf("%01d: %s\n", $i, $a[$i]); }