Skip to content

Commit

Permalink
{ifset} macro can also check block existence ( {ifset #head} {/ifset} )
Browse files Browse the repository at this point in the history
  • Loading branch information
redhead committed Feb 5, 2011
1 parent cb93254 commit 274a8f7
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Nette/Templates/Filters/LatteMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class LatteMacros extends Nette\Object
'elseif' => '<?php elseif (%%): ?>',
'else' => '<?php else: ?>',
'/if' => '<?php endif ?>',
'ifset' => '<?php if (isset(%%)): ?>',
'ifset' => '<?php if (isset(%:macroIfset%)): ?>',
'/ifset' => '<?php endif ?>',
'elseifset' => '<?php elseif (isset(%%)): ?>',
'foreach' => '<?php foreach (%:macroForeach%): ?>',
Expand Down Expand Up @@ -705,6 +705,29 @@ public function macroCache($content)



/**
* {ifset ...}
*/
public function macroIfset($content)
{
$s = "";
$i = 0;
while(($name = $this->fetchToken($content)) != null) {
if($i != 0)
$s .= ',';
if(String::startsWith($name, '#')) {
$name = ltrim($name, '#');
$s .= "\$_l->blocks['$name']";
} else {
$s .= $name;
}
$i++;
}
return $s;
}



/**
* {foreach ...}
*/
Expand Down

0 comments on commit 274a8f7

Please sign in to comment.