Determining "no entries to print"

Discussion corner for Developers of Serendipity.
Post Reply
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Determining "no entries to print"

Post by Don Chambers »

Most templates use a format to iterate through entries or to determine that there are no entries to print:

Code: Select all

{foreach from=$entries item="dategroup"}
    {foreach from=$dategroup.entries item="entry"}
        .... do entry stuff here....
    {/foreach}
{foreachelse}
    {if not $plugin_clean_page}
    <p class="nocontent">{$CONST.NO_ENTRIES_TO_PRINT}</p>
    {/if}
{/foreach}
I am working on a theme where I want to know right away in entries.tpl if there are no entries rather than wait until the {foreachelse} and {if not $plugin_clean_page} to print the "no entries" message.

Is there a good reason why, before the nested {foreach}'s that I couldn't just do a quick {if !$entries}? Is there a negative side to this?
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Determining "no entries to print"

Post by Timbalu »

I assume you will never see and get a "wait" here, while these arrays are small and PHP foreach loops so fast! So this -more or less- is a theoretical question.

You can use php_functions there: isset(), empty(), count(), sizeof("isAliasOf count"), in_array(), is_array(), voting for {if !empty($entries)}if you have to{/if}, which consumes time too.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Determining "no entries to print"

Post by Don Chambers »

Thanks Ian.
=Don=
Post Reply