Skip to content

Commit

Permalink
Adding callback support to elements. You can use the 3rd parameter to…
Browse files Browse the repository at this point in the history
… control whether or not before/afterRender callbacks should be fired for a particular element.
  • Loading branch information
markstory committed Nov 7, 2010
1 parent 1b19ad4 commit 32587c1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cake/libs/view/view.php
Expand Up @@ -309,9 +309,11 @@ function __construct(&$controller) {
* @param string $name Name of template file in the/app/views/elements/ folder
* @param array $params Array of data to be made available to the for rendered
* view (i.e. the Element)
* @param boolean $callbacks Set to true to fire beforeRender and afterRender helper callbacks for this element.
* Defaults to false.
* @return string Rendered Element
*/
public function element($name, $params = array(), $loadHelpers = false) {
public function element($name, $params = array(), $callbacks = false) {
$file = $plugin = $key = null;

if (isset($params['plugin'])) {
Expand Down Expand Up @@ -355,7 +357,13 @@ public function element($name, $params = array(), $loadHelpers = false) {
if (!$this->_helpersLoaded) {
$this->loadHelpers();
}
if ($callbacks) {
$this->Helpers->trigger('beforeRender', array($file));
}
$element = $this->_render($file, array_merge($this->viewVars, $params), $loadHelpers);
if ($callbacks) {
$this->Helpers->trigger('afterRender', array($file, $element));
}
if (isset($params['cache']) && isset($cacheFile) && isset($expires)) {
cache('views' . DS . $cacheFile, $element, $expires);
}
Expand Down

0 comments on commit 32587c1

Please sign in to comment.