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.

Problems with require_entry and no_results in build in EE 1.7.0

December 04, 2010 8:56pm

Subscribe [4]
  • #1 / Dec 04, 2010 8:56pm

    UMstratcomm

    44 posts

    Greetings,
    I am using v. 1.7.0 Build:  20101018, with MSM.

    I have been encountering some problems when using require_entry with no_results.  For example, the following code works fine (it displays an EE entry with a url_title of ‘sc_index’:

    {exp:weblog:entries dynamic="off" site="default_site" weblog="sc" url_title="sc_index" limit="1" disable="member_data|categories|trackbacks|pagination"}
    
        <h1 id="contenttitle">{title}</h1>
        {body}
        <?php /*Display latest entry date*/ if(({edit_date format="%Y-%m-%d"} > {entry_date format="%Y-%m-%d"})){ ?> Reviewed {edit_date format="%Y-%m-%d"}. <?php } else { ?> Reviewed {entry_date format="%Y-%m-%d"}.<?php } ?>
    {/exp:weblog:entries}

    However, when I add the require_entry and no_results snippets, I get redirected to my specified 404 page, even though the entry exists:

    {exp:weblog:entries dynamic="off" site="default_site" weblog="sc" url_title="sc_index" limit="1" disable="member_data|categories|trackbacks|pagination" require_entry="yes"}
           {if no_results}{redirect="404"}{/if}
           <h1 id="contenttitle">{title}</h1>
           {body}
                            
           <?php /*Display latest entry date*/ if(({edit_date format="%Y-%m-%d"} > {entry_date format="%Y-%m-%d"})){ ?> Reviewed {edit_date format="%Y-%m-%d"}. <?php } else { ?> Reviewed {entry_date format="%Y-%m-%d"}.<?php } ?>
    {/exp:weblog:entries}

    Am I missing something, or is there a valid reason why the second code snippet redirects me, even though the entry does exist?
    Thanks!
    UMStratComm

  • #2 / Dec 05, 2010 1:40am

    Why are you worried about requiring an entry and having no results if you’re specifying a known url title? Just curious….

  • #3 / Dec 05, 2010 11:13am

    UMstratcomm

    44 posts

    Why are you worried about requiring an entry and having no results if you’re specifying a known url title? Just curious….

    Mainly because the problem persists whenever I use no_results. I must be missing something with its usage, and it would be helpful to know what that is.

  • #4 / Dec 05, 2010 11:38am

    From the Docs:

    require_entry=“yes”

    This parameter tells the weblog tag that it should expect the URL to contain a valid entry ID or a valid URL title. If an ID is not found in the URL, the tag will not display any data.

    If you’re supplying a known url_title, you don’t need to require an entry; you should be getting one. And thus, probably no need for the if_no_results, as well.

  • #5 / Dec 05, 2010 6:22pm

    UMstratcomm

    44 posts

    Ok, thanks, but if I add an extra condition with the no_results snippet, the known page also returns the specified error page:

    {if segment_3 == ""}
    {!--Display Strategic Communications Index--}
    
    {!--Display SC Index--}
    
    {exp:weblog:entries dynamic="off" site="default_site" weblog="sc" url_title="sc_index" limit="1" disable="member_data|categories|trackbacks|pagination"}
         <h1 id="contenttitle">{title}</h1>
         {body}
                            
         <?php /*Display latest entry date*/ if(({edit_date format="%Y-%m-%d"} > {entry_date format="%Y-%m-%d"})){ ?> Reviewed {edit_date format="%Y-%m-%d"}. <?php } else { ?> Reviewed {entry_date format="%Y-%m-%d"}.<?php } ?>
    {/exp:weblog:entries}
    
                        
            
    {if:else}
    {!-- SC individual entries --}
    
    {exp:weblog:entries dynamic="off" site="default_site" weblog="sc" url_title="{segment_3}" limit="1" disable="member_data|categories|trackbacks|pagination" require_entry="yes"}
    
         {if no_results}
              {redirect="ums/errordocument"}
         {/if}
         <h1 id="contenttitle">{title}</h1>
         {body}
                            
         <?php /*Display latest entry date*/ if(({edit_date format="%Y-%m-%d"} > {entry_date format="%Y-%m-%d"})){ ?> Reviewed {edit_date format="%Y-%m-%d"}. <?php } else { ?> Reviewed {entry_date format="%Y-%m-%d"}.<?php } ?>
    {/exp:weblog:entries}
            
    {/if}

    In this case, the first condition (SC Index: the page that I know to exist) ALWAYS displays the redirected error page, even though I know that it exists.  If I remove the no_results snippet from the other condition (SC individual entries), then the index page will display…But then I have no way of throwing the 404.  That is the problem: no_results is not working like it is supposed to.  It does not matter how I use the no_results: it always causes some sort of problem.  Is it my template (displayed above), or perhaps something else?

    TY.

    Update:  Switching to a simple conditional appears to work, however.  The following variation on the above code will work for me:

    {if segment_3 == ""}
    {exp:weblog:entries dynamic="off" site="default_site" weblog="sc" url_title="sc_index" limit="1" disable="member_data|categories|trackbacks|pagination"}
         <h1 id="contenttitle">{title}</h1>
         {body}
                            
         <?php /*Display latest entry date*/ if(({edit_date format="%Y-%m-%d"} > {entry_date format="%Y-%m-%d"})){ ?> Reviewed {edit_date format="%Y-%m-%d"}. <?php } else { ?> Reviewed {entry_date format="%Y-%m-%d"}.<?php } ?>
    {/exp:weblog:entries}
    
                              
    {/if}
    {if segment_3 != ""}
    {!-- SC individual entries --}
    
    {exp:weblog:entries dynamic="off" site="default_site" weblog="sc" url_title="{segment_3}" limit="1" disable="member_data|categories|trackbacks|pagination" require_entry="yes"}
    
         {if no_results}
              {redirect="ums/errordocument"}
         {/if}
         <h1 id="contenttitle">{title}</h1>
         {body}
                            
         <?php /*Display latest entry date*/ if(({edit_date format="%Y-%m-%d"} > {entry_date format="%Y-%m-%d"})){ ?> Reviewed {edit_date format="%Y-%m-%d"}. <?php } else { ?> Reviewed {entry_date format="%Y-%m-%d"}.<?php } ?>
    {/exp:weblog:entries}
            
    {/if}

    So, perhaps the problem is related to the parse order of conditionals, or is it true that no_results will only work for single page templates or for simple conditionals?  If so, is there any way to use no_results for templates with advanced conditionals (for example, including each conditional in a separate embed)?  Ultimately, is there another recommended method for displaying 404 pages for segments beyond the template group/template?

    TY!

  • #6 / Dec 05, 2010 7:20pm

    UMstratcomm

    44 posts

    FYI-I found this post: http://ellislab.com/forums/viewthread/173595/, that basically states that one must use simple conditionals in order to utilize no_results.

  • #7 / Dec 06, 2010 3:35pm

    Ingmar

    29245 posts

    So, that works for you? Just making sure.

  • #8 / Dec 06, 2010 5:38pm

    UMstratcomm

    44 posts

    So, that works for you? Just making sure.

    ...Unless there are other options?

  • #9 / Dec 07, 2010 7:49am

    Sue Crocker

    26054 posts

    Simple conditionals work, I’d stay with that solution. Don’t hesitate to post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases