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.

Blank segments - am I missing something?

July 04, 2012 6:34am

Subscribe [4]
  • #1 / Jul 04, 2012 6:34am

    Steve Abraham

    149 posts

    Let’s make a couple of assumptions first:

    - Strict URL setting is enabled.
    - “Segment X” is blank/non-existant.

    {exp:channel:entries channel="[CHANNEL]" dynamic="no" url_title="{segment_x}" require_entry="yes" limit="1"}
    
     {if no_results}
      {redirect="404"}
     {/if}
    
     {url_title}
    
    {/exp:channel:entries}

    To my mind this should throw a 404, or at the very least just show a blank template. What in fact happens though, is it spits out the url_title of the last entry in [CHANNEL].

    Now; is this expected behaviour (if so it doesn’t seem right), or do I have something weird going on. Checked on a few installs and it seems to behave the same way in all of them.

    Having used EE for years on countless installs I can’t quite get my head round why I’m only noticing this now.

  • #2 / Jul 04, 2012 6:42am

    johnwbaxter

    651 posts

    What happens if you take out limit=1 ?

  • #3 / Jul 04, 2012 6:44am

    Max Lazar

    341 posts

    I just check it on my install (ee 2.5.2), works just fine:
    Status: 404 Page Not Found

  • #4 / Jul 04, 2012 6:47am

    Max Lazar

    341 posts

    just for sure - what do you have for “404 Page” setting?

  • #5 / Jul 04, 2012 6:54am

    Steve Abraham

    149 posts

    What happens if you take out limit=1 ?

    I get *every* url_title from that channel…

  • #6 / Jul 04, 2012 6:55am

    Steve Abraham

    149 posts

    just for sure - what do you have for “404 Page” setting?

    Bizarre it’s working for you - utterly bizarre…

    My 404 is set to a working 404 page.

  • #7 / Jul 04, 2012 6:56am

    Steve Abraham

    149 posts

    I should also add, removing require_entry makes no difference to anything.

  • #8 / Jul 04, 2012 6:57am

    johnwbaxter

    651 posts

    Good, just checking….

  • #9 / Jul 04, 2012 7:08am

    Steve Abraham

    149 posts

    We’ve now tested this and getting the same behaviour on 3 different hosting environments; bog standard Apache, FastCGI PHP+Apache and Apache+custom worker module, no difference.

    Also removed .htaccess, also no difference.

    Tested on two currently live EE sites and one brand new fresh install, no difference.

  • #10 / Jul 04, 2012 7:10am

    Max Lazar

    341 posts

    I just tested it on v2.4.0 (20120123):
    - if blank - no 404, just last entry
    - if some wrong url_title - 404

  • #11 / Jul 04, 2012 7:11am

    Steve Abraham

    149 posts

    I just tested it on v2.4.0 (20120123):
    - if blank - no 404, just last entry
    - if some wrong url_title - 404

    Yep, that’s the results I’m seeing - but I’m getting them on 2.5.0 and 2.5.2…

  • #12 / Jul 04, 2012 7:24am

    Max Lazar

    341 posts

    as solution -  put the space before {segment_x} 😊

    url_title=" {segment_x}"

    So why it is happend:
    1. require_entry works only if you have dynamic=“yes” - so in your example is just ignored
    2. for blank segment channel is ignore url_title as parameter

    I can say that for blank segment case you have next template

    {exp:channel:entries channel="[CHANNEL]" dynamic="no" limit="1"}
    
     {if no_results}
      {redirect="404"}
     {/if}
    
     {url_title}
    
    {/exp:channel:entries}
  • #13 / Jul 04, 2012 7:34am

    Steve Abraham

    149 posts

    That’s interesting, Max - though the space before the segment feels a little “hacky”...! :D

    I think the answer for now is that I just wrap the whole channel:entries tag in a conditional that checks the segment is not blank.

  • #14 / Jul 04, 2012 7:44am

    Max Lazar

    341 posts

    I think the answer for now is that I just wrap the whole channel:entries tag in a conditional that checks the segment is not blank.

    agree - this is right way

  • #15 / Jul 05, 2012 11:00am

    Shane Eckert

    7174 posts

    Hey Steve,

    Where are you at now? There have been a lot of responses, are you back in business?

    Please let me know.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases