Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    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]
    Thread Starter philipt18

    (@philipt18)

    Amazing, thank you.

    Thread Starter philipt18

    (@philipt18)

    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.

    Thread Starter philipt18

    (@philipt18)

    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?

    Plugin Author Eliot Akira

    (@miyarakira)

    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]
    Thread Starter philipt18

    (@philipt18)

    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.

    Thread Starter philipt18

    (@philipt18)

    or is it simply:

    `[if var=total value=0]
    ..One or more loops were empty..
    [/if]’

    Plugin Author Eliot Akira

    (@miyarakira)

    Yes, that last one should work.

    Thread Starter philipt18

    (@philipt18)

    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.

    Plugin Author Eliot Akira

    (@miyarakira)

    Oops, you’re right, the check for empty or zero value was not working right. Please try it with the newest plugin update.

    Thread Starter philipt18

    (@philipt18)

    Now working, thanks.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘If the loop doesn't exist’ is closed to new replies.