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.

Related entries: {if no_related_entries} not working

September 27, 2011 9:08pm

Subscribe [3]
  • #1 / Sep 27, 2011 9:08pm

    jackmcpickle

    21 posts

    Greetings.

    I’ve searched for this and noticed that there seems to have been a few related entries issues in the last couple builds. I’m running v2.2.2 - Build: date 20110801 and the {if no_related_entries} conditional doesn’t seem to work.

    I’ve set up basic related entries and it works fine if an entry is selected, but when nothing is selected (regardless of whether it is selected and then removed, or whether it has never been selected) I get {REL[0][linked_articles]cafbxuHyREL}.

    I assumed at first that this was perhaps the default behaviour if no related entry was selected, and attempted to use:

    {if no_related_entries}
      Content here
    {/if}

    But it seems to have no effect. I’ve checked the Api_channel_entries.php as suggested here https://support.ellislab.com/bugs/detail/14477/#9839 but my file already has the ‘fix’.

    My code is:

    {related_entries id="linked_articles"}
     
    {if no_related_entries}
      No related article
     {/if}
    
    <h2>{title}</h2>
    <p>                    {summary}<br />
    <a href="http://{page_url}">Find out more</a><br />
                    {/related_entries}

    Am I doing something wrong, or is this a bug?

    Cheers.

     

  • #2 / Sep 28, 2011 10:49am

    Mark Bowen

    12637 posts

    Hi Jack,

    Do you have the code you’ve shown above within a Channel Entries Tag or just on its own? Could you show a little more of your code here please.

    I just tried on a very basic relationships setup with that code inside a Channel Entries tag and for entries that didn’t have a relationship selected I got the {if no_related_entries} message appearing and for those that did have a relationship selected I got the {title} shown.

    Also when you say “when nothing is selected” I’m just wondering what you mean by this? What are you selecting and where?

    Thanks,

    Mark

  • #3 / Sep 28, 2011 8:04pm

    jackmcpickle

    21 posts

    Hi Mark,

    The full code is

    {exp:channel:entries channel="home" limit="1" disable="member_data|trackbacks|categories"}
      <div class="content">
       <div class="wrapper">
        <div class="homepage_feature one">
           {related_entries id="homepage_feature_1"}
    
                {if no_related_entries}
                   No related article
                {/if}
    
                <h2>{title}</h2>
    <p>            {exp:word_limit total="30"}{summary}{/exp:word_limit}<br />
                <a href="http://{page_url}">Find out more</a><br />
            {/related_entries}<br />
        </div><br />
       </div><br />
      </div><br />
    {/exp:channel:entries}

    What I meant by nothing selected was no relationship exists - ie the no_related_entries if statement should be executed. Instead I just get {REL[0][homepage_feature_1]38ZQnxtEREL} <- this kind of thing printed. This displays whether I have the if statement included in the template or not.

  • #4 / Sep 30, 2011 11:13am

    Dan Decker

    7338 posts

    Hi Jack,

    I mimicked your set up trying to replicate this, but I got no/results as expected. Are you using any third-party field types in this channel or anything else that might be affecting this? What do you see if you reduce {exp:channel:entries} to simply:

    {exp:channel:entries channel="home"}

    Leaving all the rest the same?

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

ExpressionEngine News!

#eecms, #events, #releases