Location: PHPKode > scripts > Claw > claw/ext/PHPClawRenderer.php
<?php

/**
 * Native PHP Template Renderer for Claw Framework
 *
 * @author Tomas Varaneckas <tomas [dot] varaneckas [at] gmail [dot] com>
 * @package claw.ext
 * @version $Id: PHPClawRenderer.php 136 2006-04-02 23:13:52Z spajus $
 * @todo implementation + testing + ajaxification
 * @todo FIXME - broken
 */
class PHPClawRenderer implements ClawRenderer
{
	/**
	 * Current template filename
	 *
	 * @var string
	 */
	private $template;

	/**
	 * Template parts for inclusion
	 *
	 * @var Array
	 */
	private $parts = array();

	/**
	 * Template variables
	 *
	 * @var Array
	 */
	private $vars = array();

	/**
	 * Template engine configuration
	 *
	 * @var Array
	 */
	private $config = array();

	/**
	 * Constructor
	 */
	public function __construct()
	{
		$cfg = Claw::getClaw()->getConfig();
		$this->config = $cfg->get('claw_renderer', 'config');
	}

	/**
	 * Assigns array of variables to template engine
	 *
	 * @param Array $vars Array of variables to assign
	 */
	public function assignVars($vars)
	{
		if (is_array($vars))
		{
			$this->vars = array_merge($this->vars, $vars);
		}
	}

	/**
	 * Assigns variable to template engine
	 *
	 * @param string $var Name
	 * @param mixed $value Value
	 */
	public function assign($var, $value)
	{
		$this->vars[$var] = $value;
	}

	/**
	 * Sets main template file
	 *
	 * @param string $tpl Path to template file
	 */
	public function setTemplate($tpl)
	{
		$this->template = $this->config['template_dir']
			. DIRECTORY_SEPARATOR . $tpl;
	}

	/**
	 * Sets inclusive template part
	 *
	 * @param string $name Name of template part
	 * @param string $tpl Path to template part file
	 */
	public function setTemplatePart($name, $tpl)
	{
		$this->parts[$name] = $this->config['template_dir']
			. DIRECTORY_SEPARATOR . $tpl;
	}

	/**
	 * Returns rendered output
	 *
	 * @return string
	 */
	public function render()
	{
		if ($this->template)
		{
			extract($this->vars, EXTR_REFS);
			$tpl = new PHPClawRendererLib($this->config, $this->parts, $this->vars);
			return include_once $this->template;
		}
	}
	
	public function addHelper($name, ClawRendererHelper $helper)
	{
		//TODO implement
	}
}
?>
Return current item: Claw