Is there a graceful way to return no results?
First: great add-on. So much better for my purposes than Solspace Calendar.
I do have a question, however. I'm using Low Events to manage readings for a publisher. There is a general calendar page, but readings are also embedded into the individual authors' pages.
The problem I'm having is this:
I have the Low Events entries tag configured to hide past events, which works great. But I'd like the entries loop to return one simple "No results" string when it doesn't find any upcoming events.
The only problem is that by using a conditional like {if no_results} I get that string for however many "expired" events the loop finds in the database.
I'm probably doing something really stupid. Here's the code:
{exp:low_events:entries entry_id='{embed:entry_id}' limit="5" show_passed="no"}
<!-- Content here -->
{if no_results}
<p>There are currently no readings planned.</p>
{/if}
{/exp:low_events:entries}
I'm calling the embed via Playa, like so:
{exp:playa:parents channel="calendar_events"}
{embed='embeds/cal_by_author' entry_id='{entry_id}'}
{/exp:playa:parents}
What am I missing?
Thanks again for a great add-on.
Replies
Low 30 Jul 2012 18:39
Hi Adam,
Are you nesting the tag inside another, perhaps? If so, have you tried using this instead of the regular no_results conditional:
Adam McIsaac 30 Jul 2012 19:21
I have tried the low_events_no_results tag, but only within the entries tag. I get the same result: it sends the proper string, but it sends a copy of it for each passed event, e.g.:
{exp:low_events:entries entry_id='{embed:entry_id}' show_passed_events="no"}
<!-- content -->
{if low_events_no_results}
<p>There are currently no readings planned.</p>
{/if}
{/exp:low_events:entries}
will output, for example, two copies of of "There are currently..." if there are two passed events. It will then output upcoming events as well, if there are any.
Low 30 Jul 2012 19:27
You're calling the embed inside the playa:parents tag, so if there are multiple entries there, the embed (and thus the low_events:entries tag) will get called multiple times. That could trigger the no_results bit to show multiple times.
How about using the parent_ids tag instead? Something like this:
Adam McIsaac 30 Jul 2012 20:02
Ah. I suspected it was a problem with how I was implementing the embed. I'll see what I can do; the challenge is that Playa is actually getting results, it's just not displaying them. If I figure it out, I'll post the solve here. Thanks a tonne.
Adam McIsaac 21 Aug 2012 14:29
Okay, I figured it out, and am posting this here in case some other noob runs into the same problem.
Basically, my mistake was using Playa as a loop, because as Low pointed out it was calling the Low Events loop for every parent.
This worked:
{if '{exp:playa:parent_ids}' > 0}
{embed='embeds/cal_by_author' entry_ids='{exp:playa:parent_ids channel="events" field="cal_event-author"}'}
{if:else}
<article>
<div class="text">
<p>There are currently no events scheduled featuring this author.</p>
</div>
</article>
{/if}
With the embed looking something like this:
{exp:low_events:entries entry_id='{embed:entry_ids}' unit="upcoming"}
<!-- Embed code -->
{if low_events_no_results}
<article>
<div class="text">
<p>There are currently no events scheduled featuring this author.</p>
</div>
</article>
{/if}
{/exp:low_events:entries}
You'll notice that there are two conditionals for returning no results: one in the original embed call, and one in the embed code itself. This is because if the variable "entry_ids" is empty (entry_id=""), Low Events still will return the most recent entry. So the first conditional tests for whether or not there are any parent IDs to send to the embed; if there are not, the call is cancelled. I don't think this is a problem with Low Events, by the way; it's a byproduct (not a bug) of Playa interacting with the quasi-statuses Low Events uses to treat past events.
Low 21 Aug 2012 14:36
Cool, glad you worked it out.
Having the no_results bit in 2 places is fine here. It's even a bit better than leaving it up to the embed: the embed doesn't even take place if there are no parent ids, which is better for performance.
You could even put the no_results message in a global variable to keep it even DRYer.