Exemplo n.º 1
0
	/**
	 * Includes subtemplate.
	 * @param  mixed      included file name or template
	 * @param  array      parameters
	 * @param  ITemplate  current template
	 * @return NTemplate
	 */
	public static function includeTemplate($destination, array $params, ITemplate $template)
	{
		if ($destination instanceof ITemplate) {
			$tpl = $destination;

		} elseif ($destination == NULL) { // intentionally ==
			throw new InvalidArgumentException("Template file name was not specified.");

		} elseif ($template instanceof IFileTemplate) {
			if (substr($destination, 0, 1) !== '/' && substr($destination, 1, 1) !== ':') {
				$destination = dirname($template->getFile()) . '/' . $destination;
			}
			$tpl = clone $template;
			$tpl->setFile($destination);

		} else {
			throw new NotSupportedException('Macro {include "filename"} is supported only with IFileTemplate.');
		}

		$tpl->setParameters($params); // interface?
		return $tpl;
	}