Determining "no entries to print"

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

Determining "no entries to print"

Post by Don Chambers » Tue Jan 26, 2016 3:54 am

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?

User avatar
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Determining "no entries to print"

Post by Timbalu » Tue Jan 26, 2016 10:58 am

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

User avatar
Don Chambers
Regular
Posts: 3628
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Re: Determining "no entries to print"

Post by Don Chambers » Tue Jan 26, 2016 5:04 pm

Thanks Ian.

Post Reply