Source for file SnippetHelper.php
Documentation is available at SnippetHelper.php
6: * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
8: * This source file is subject to the "Nette license" that is bundled
9: * with this package in the file license.txt.
11: * For more information please see https://nette.org
13: * @copyright Copyright (c) 2004, 2009 David Grudl
14: * @license https://nette.org/license Nette license
15: * @link https://nette.org
17: * @package Nette\Templates
23: require_once dirname(__FILE__) .
'/../../Object.php';
28: * Control snippet template helper.
30: * @author David Grudl
31: * @copyright Copyright (c) 2004, 2009 David Grudl
32: * @package Nette\Templates
37: public static $outputAllowed =
TRUE;
45: /** @var ArrayObject */
54: * Starts conditional snippet rendering. Returns SnippetHelper object if snippet was started.
55: * @param Control control
56: * @param string snippet name
57: * @param string start element
58: * @return SnippetHelper
60: public static function create(Control $control, $name =
NULL, $tag =
'div')
62: if (self::$outputAllowed) { // rendering flow or non-AJAX request
65: if ($obj->tag) echo '<', $obj->tag, ' id="', $control->getSnippetId($name), '">';
66: return $obj; // or string?
68: } elseif ($control->isControlInvalid($name)) { // start snippet buffering
70: $obj->id =
$control->getSnippetId($name);
71: $obj->payload =
$control->getPresenter()->getPayload();
74: self::$outputAllowed =
TRUE;
85: * Finishes and saves the snippet.
90: if ($this->tag !==
NULL) { // rendering flow or non-AJAX request
91: if ($this->tag) echo "</$this->tag>";
93: } else { // finish snippet buffering
97: if (empty($this->payload->snippets)) { // PHP 5.2.0 bug workaround
98: $this->payload->snippets =
new ArrayObject;
101: self::$outputAllowed =
FALSE;