Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Latte/Runtime/ISnippetBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ interface ISnippetBridge
function isSnippetMode();


/**
* @param bool
* @return void
*/
function setSnippetMode($snippetMode);


/**
* @param string
* @return bool
Expand Down
6 changes: 4 additions & 2 deletions src/Latte/Runtime/SnippetDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(ISnippetBridge $bridge)

public function enter($name, $type)
{
if (!$this->bridge->isSnippetMode()) {
if (!$this->renderingSnippets) {
return;
}
$obStarted = FALSE;
Expand All @@ -63,7 +63,7 @@ public function enter($name, $type)

public function leave()
{
if (!$this->bridge->isSnippetMode()) {
if (!$this->renderingSnippets) {
return;
}
list($name, $obStarted) = array_pop($this->stack);
Expand All @@ -88,13 +88,15 @@ public function renderSnippets(array $blocks, array $params)
return FALSE;
}
$this->renderingSnippets = TRUE;
$this->bridge->setSnippetMode(FALSE);
foreach ($blocks as $name => $function) {
if ($name[0] !== '_' || !$this->bridge->needsRedraw(substr($name, 1))) {
continue;
}
$function = reset($function);
$function($params);
}
$this->bridge->setSnippetMode(TRUE);
$this->bridge->renderChildren();
return TRUE;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/Latte/mocks/SnippetBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public function isSnippetMode()
}


public function setSnippetMode($snippetMode)
{
$this->snippetMode = $snippetMode;
}


public function needsRedraw($name)
{
return $this->invalid === TRUE || isset($this->invalid[$name]);
Expand Down