Is it possible to check whether channel entries exist. Something like the following?
{if channel entries}
<h1>Results</h1>
<ul>
<li>{title}</li>
</ul>
{if:else}
Sorry No Results
{/if}Thanks
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
November 14, 2012 7:19pm
Subscribe [2]#1 / Nov 14, 2012 7:19pm
Is it possible to check whether channel entries exist. Something like the following?
{if channel entries}
<h1>Results</h1>
<ul>
<li>{title}</li>
</ul>
{if:else}
Sorry No Results
{/if}Thanks
#2 / Nov 14, 2012 8:09pm
Hi Kippbrady,
There isn’t any tag like that. Why don’t you use channel:entries tag for the same purpose.
Best Regards,
#3 / Nov 14, 2012 8:18pm
To follow up on what Bhashkar suggested - the channel entries loop will natively not return anything if the channel doesn’t contain any entries based on what your loop’s parameters call for, so effectively the channel entries loop already does what you are looking for. Based on what you indicated you wanted, you would have a simple structure such as:
{exp:channel:entries channel="channel_name" orderby="date" sort="desc" disable="whatever|you|don't|need" dynamic="no"}
{if no_results}
Sorry No Results
{/if}
{if count == "1"}<h1>Results</h1>
<ul>{/if}
<li>{title}</li>
{if count == total_results} </ul>{/if}
{/exp:channel:entries}Note I simply wrapped your title and the opening of the unordered list with a conditional that would present it only prior to the first entry returned by the loop, and likewise closed the unordered list only after the last entry returned by the loop. Other that that, the loop would return only a title per entry, wrapped with <li></li>.
#4 / Nov 14, 2012 8:29pm
Thanks John,
Thanks for elaborating.
#5 / Nov 15, 2012 4:41am
Thanks for the replies. The above code was meant to be pseudocode for what I’m trying to achieve.
Forgive I’m coming over from Wordpress and I’m trying to replicate the way I’d do things in that.
Thanks again.