Plugin

Developer
Supported

Switchee

ExpressionEngine 1.x, ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4

Back to this add-on's main page
View Other Add-ons From Mark Croxton

     

You must be logged in to post.

no_results for channel:entries tag within switchee causes it to disappear entirely

Bug Report

Eric L
Eric L

I’ve discovered an apparent bug where, if a channel:entries tag returns no results AND is the first channel:entries tag within a switchee case, it will disappear entirely—not even showing its if_no_results content.
I’m running EE 2.2.2 and Switchee 2.0.2 beta. Here’s my test page:

{exp:switchee variable '{segment_2}' parse='inward'}
    {case 
default='yes'}

{
!-- c:e tag 1 --}
{exp
:channel:entries channel="channel_1" username="bob"}
 channel entries tag 1
{if no_results}
 channel entries tag 1 [no results]
{
/if}
{
/exp:channel:entries}

{
!-- c:e tag 2 --}
{exp
:channel:entries channel="channel_2" username="bob"}
 channel entries tag 2
{if no_results}
 channel entries tag 2 [no results] 
{
/if}
{
/exp:channel:entries}

{
!-- c:e tag 3 --}
{exp
:channel:entries channel="channel_3" username="bob"}
 channel entries tag 3
{if no_results}
 channel entries tag 3 [no results] 
{
/if}
{
/exp:channel:entries}

    {
/case}
{
/exp:switchee} 


- If c:e tag 1 returns an entry for our user bob, all tags display correctly, whether bob has any entries for the other channels or not.
- If c:e tag 1 returns no results, it does not display anything, not even the no_results content. All other tags display correctly, regardless of results.
- If all three tags return no results, you can change the order around and whichever is first will not display.
- If you remove the switchee statement, all the c:e tags display correctly.

And the really weird one:
- As in the first example, if c:e tag 1 has results but tag 3 does not, everything is fine. But if you duplicate tag 3 and place a copy of it before tag 1 (i.e. first within the switchee case), neither copy of tag 3 will display.

Mark Croxton
# 1
Developer
Mark Croxton

The {if no_results} behaviour is ‘owned’ by the outer wrapping tag not the inner tag. This is an EE bug/feature and not unique to Switchee.

Because of this, Switchee has it’s own no_results handling which will work for each nested switchee layer:

{if switchee_no_results}
...
{/if} 

 

Eric L
# 2
Eric L

I saw the switchee_no_results info in the readme, only I didn’t get that it should be used within the wrapped tags. But yeah, that fixed it, so thanks for clarifying. And thanks for creating such a great add-on!