ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

[SOLVED] How to know if there are entries before calling exp:channel:entries?

August 21, 2010 6:29pm

Subscribe [1]
  • #1 / Aug 21, 2010 6:29pm

    Rick Jolly

    729 posts

    I’m using EE 2 and I’m very new.

    I don’t want to display a list unless I have entries since I’d have invalid html:

    <ul>
       {exp:channel:entries channel="test"}
          <li>{title}</li>
       {/exp:channel:entries}
    </ul>

    I can’t nest EE tags like this:

    {exp:channel:entries channel="test"}
       {if no_results}
          <!-- Is there no opposite of no_results? -->
       {if:else}
          <ul>
             {exp:channel:entries channel="test"}
                <li>{title}</li>
             {/exp:channel:entries}
          </ul>
       {/if}
    {/exp:channel:entries}

    Using PHP, I’d either do a count() query before getting the entries, or I’d get the entries first, and only if some entries existed would I print the list.

  • #2 / Aug 21, 2010 7:15pm

    Green Egg Media

    111 posts

    Rick Jolly -

    You have a few options. You could do something like this, for example:

    {exp:channel:entries channel="test" dynamic="no" limit="1" disable="categories|member_data|pagination"}
       {if count > 0}
          {embed="embed_template_group/embed_template"}
       {/if}
    {/exp:channel:entries}

    Note that in the channel entries tag, I’ve restricted it significantly. Essentially, this to limit the load on the DB and just return a single entry, allowing you to determine whether or not there are any entries at all. If you need to know whether there are more than 1, you’ll need to modify the parameters. Then, in the embedded template, you would make the actual list, like so:

    <ul>
    {exp:channel:entries channel="test" dynamic="no"}
       <li>{title}</li>
    {/exp:channel:entries}
    </ul>

    There are other options, but this one should work for you.

    Lance
    Green Egg Media

  • #3 / Aug 21, 2010 7:31pm

    Rick Jolly

    729 posts

    Thanks so much! That is exactly what I needed.

    If I still have your attention, another developer somehow added automatic html list tags to {exp:channel:entries channel="test"} and I’m wondering how to find this setting.

    So this:

    {exp:channel:entries channel="test" dynamic="no"}
       {title}
    {/exp:channel:entries}

    automatically gets rendered as this:

    <ul>
       <li>title</li>
    </ul>
  • #4 / Aug 21, 2010 7:40pm

    Green Egg Media

    111 posts

    It sounds like the developer was either using a plugin or an extension of some type to accomplish this. This isn’t a built-in feature of EE, at least not one I’ve encountered, and certainly not one that’s documented.

    I recommend asking the particular developer who had done this how to do it.

    Lance
    Green Egg Media

  • #5 / Aug 21, 2010 7:51pm

    Rick Jolly

    729 posts

    Ok, thanks so much.

  • #6 / Aug 21, 2010 8:05pm

    Green Egg Media

    111 posts

    NP, glad to help.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases