In the latest plugin update, I added a way to display something when [loop exists] returns empty.
[loop exists ...]
[the-loop]
..
[/the-loop]
[if empty]
Nothing found. <----
[/if]
[/loop]
I just realized something. In my code I have content before and after the [the-loop]. For example:
[loop exists]
<table>
[the-loop]
<tr><td>[field title]</td></tr>
[/the-loop]
</table>
[/loop]
In your example, where [if empty] is placed right after the [the-loop], what would the right syntax be when there is content after [the-loop]? Would it make more sense to put the [if empty] code after the [/loop]? of would you just put it like:
[loop exists]
<table>
[the-loop]
<tr><td>[field title]</td></tr>
[/the-loop]
</table>
[if empty]
Nothing found.
[/if]
[/loop]
Thanks.
Hmmm, I tried something like the above, but the problem is that I’m passing a list to the loop exists, and it cycle through five times, and each time it’s empty it shows me the code for when it’s empty. Is there a way to display a single result for all five passes?
The last code you posted looks good – if nothing exists, it will display only what’s within [if empty] – so it will not display a table.
As for passing a list and showing a single result.. You might be able to achieve it with the Math module (enabled under Settings), to count the number of empty loops.
[set total]0[/set]
[pass list..]
[loop]
..some loops..
[calc]total = total + 1[/calc]
[/loop]
[/pass]
[if var=total value=0 compare=more]
..One or more loops were empty..
[/if]
Interesting. That would work in this case because I know how many times the loop goes around. But what if I only want to to show the content when all the loops were empty? Something like?:
[if var=total value=0 compare=equals]
..If all loops were empty..
[/if]
I couldn’t find compare=equals, so I’m guessing that’s not exactly right. What’s the right way to do that?
Thanks.
or is it simply:
`[if var=total value=0]
..One or more loops were empty..
[/if]’
Yes, that last one should work.
Hmm. Doesn’t seem to work. I have the [set] before [pass] and [loop exists] then the [calc] +1 in [the-loop], and the [if var…] after the [/pass]. I then load a page that has not children, which should mean the value of total is still zero, but it doesn’t execute the if code.
Oops, you’re right, the check for empty or zero value was not working right. Please try it with the newest plugin update.