n:if activerow in latte template
Notice: This thread is very old.
- pistols
- Member | 26
hello there,
I have a question about the n:if macro.
my model does something like this:
<?php
return $this->database->table(self::TABLE_NAME)->where(self::COLUMN_ROLE, $type);
?>
and my presenter puts that activerow directly into my template.
My problem is with the n:if makro
if I do this:
<div n:if="values">
Yap!, you have some nicely crafted values there!
</div>
evaluates always true… even when i have no returned data from my model.
I dumped the active row, and indeed it is a live object (TRUE). but with no data…
could you point me how to nicely hide the div if my result set is empty?
thanks
- David Matějka
- Moderator | 6445
ActiveRow cannot be “empty”, only Selection can. On Selection you can do something like this:
<div n:if="count($values)">
...
</div>
- Oli
- Member | 1215
I know 2 diferent ways.
- In your method make decision if database returned any data:
public function findRole()
{
return $this->myReturn($this->database->table(self::TABLE_NAME)->where(self::COLUMN_ROLE, $type));
}
protected function myReturn($return)
{
if (count($return) == 0) {
$return = false;
}
return $return;
}
It will work with your usage if.
- Didn't test if some data were returned and put into n:if count of rows
<div n:if="count(values) > 0"> // or you can use values->count() > 0
Yap!, you have some nicely crafted values there!
</div>