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.

Segment_1 not working as expected

August 10, 2010 10:14am

Subscribe [4]
  • #1 / Aug 10, 2010 10:14am

    dombi

    130 posts

    I am trying to display some content on the first page of my site. But I don’t want to display it on the 2nd, 3rd, ... pages.
    I am using segments to achieve this, but for some reason it is not working.


    Basically I am checking if segment_1 exists. If the value is nothing, then I am probably still on the first page and I can display the content. If the value is P0, then I am still on the first page, and I can display the content.

    This is the code, that I am using.

    {if segment_1 == "" OR segment_1 == " " OR segment_1 == "P0"}
    content
    {/if}

    My problem is, that for some reason, the content still shows up on all the other pages (2nd, 3rd, etc.).
    I narrowed down the problem to the first section of the condition:

    segment_1 == ""

    If I remove this, the content is not displayed on the 2nd, 3rd, etc. pages. But it is also missing from the 1st page. If I add the condition back, the content appears on the 1st page, but it also appears on the other ones.

    Any ideas on what I might be doing wrong? Or is there a better way to do this?

    Thanks!

  • #2 / Aug 10, 2010 10:44am

    optima

    121 posts

    Are you using the same template for your 1st, 2nd, 3rd pages or are you trying to achieve this in a global embed?

  • #3 / Aug 10, 2010 10:49am

    dombi

    130 posts

    I am trying to use this on our index page, which is re-used on the 2nd, 3rd, etc. pages.
    So, I think I am trying to achieve a global embed.

  • #4 / Aug 10, 2010 10:52am

    optima

    121 posts

    So you don’t have separate templates for your 2nd and 3rd pages?

  • #5 / Aug 10, 2010 10:57am

    dombi

    130 posts

    No, I don’t want to have separate pages for those….

  • #6 / Aug 10, 2010 11:07am

    optima

    121 posts

    It sounds like you are using weblog pagination on your websites homepage, is that correct?

    If so, I think the first segment will be evaluated empty even with the pagination segment (P0, P1, P2, etc) in the URI.

  • #7 / Aug 10, 2010 12:07pm

    dombi

    130 posts

    But if that is the case, is segment doing the right thing? Isn’t is supposed to return P0, P1, etc?

  • #8 / Aug 10, 2010 12:14pm

    optima

    121 posts

    Actually yes, if I try put this:

    {if segment_2}Has segment 2{/if}

    in a template where I use pagination then I only see “Has segment 2” when P0, P10, etc is in the URI.

  • #9 / Aug 10, 2010 12:25pm

    optima

    121 posts

    This worked for me:

    {if segment_2== "" OR segment_2 == "P0"}This is the first page{/if}

    My URLs are structured as follows:

    http://www.mydomain.com/template_group/
    http://www.mydomain.com/template_group/P0/
    http://www.mydomain.com/template_group/P10/

    and the above conditional only evaluates true for the first two URLs

  • #10 / Aug 10, 2010 1:13pm

    dombi

    130 posts

    Well, it is not working. I tried the following:

    {if segment_1}do nothing
    {if:else}show content{/if}

    Still, content shows up on all the pages.

  • #11 / Aug 10, 2010 1:16pm

    optima

    121 posts

    What do your URLs look like?

  • #12 / Aug 10, 2010 1:19pm

    dombi

    130 posts

  • #13 / Aug 10, 2010 1:30pm

    optima

    121 posts

    Not sure whats going on then, might be worth posting your entire template code.

  • #14 / Aug 10, 2010 1:35pm

    dombi

    130 posts

    I might try to see if there is any way to do it with php.
    Thank you for your help optima!

  • #15 / Aug 11, 2010 4:00am

    John Henry Donovan

    12339 posts

    dombi,

    What version and build of EE are you using?
    Always finish the other half of the condition

    {if segment_1 == ""}do nothing
    {if:else}show content{/if}

    http://www.website.com/index.php/P10
    http://www.website.com/index.php/P20
    http://www.website.com/index.php/P30

    What happens if you put the template group in your URLs

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

ExpressionEngine News!

#eecms, #events, #releases