n:ifcontent doesn't work if var is not set, and also PHP throws no notice
- Raoul
- Member | 7
Example:
<div n:ifcontent="$foo">Content</div>
The div is shown if $foo is not set and PHP doesn't raise a notice.
When I use
<div n:if="$foo">Content</div>
The PHP Notice is:
PHP Notice: Undefined variable: foo
I thought n:ifcontent
works like when I use
!empty()
in an if
condition.
- Raoul
- Member | 7
Thanks all, so I just wrote two macros if you are interested:
$set->addMacro('notempty', 'if (!empty(%node.args)) {', '}');
$set->addMacro('empty', 'if (empty(%node.args)) {', '}');
I use them only in this way:
<div n:empty="$foo">Content</div>
<div n:notempty="$foo">Content</div>
so the div
tag is or isn't shown
- David Grudl
- Nette Core | 8218
And it's not enough to use n:if="empty($foo)"
?
Instead od notempty, you can use n:ifset="$foo"
(as if
(isset($foo))