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.

Getting a segment_1 from a page url

July 21, 2008 1:00pm

Subscribe [3]
  • #1 / Jul 21, 2008 1:00pm

    Fusion Design

    128 posts

    Hi there,
    Is there any way to have an if conditional where you reference only part of a page url.

    For example:

    {if page_url == "{exp:fetch_current_uri uri-only='yes'}"}
      class="navon"
    {if:else}
      class="nav"
    {/if}


    will work for the link index.php/about_us/key_people/ when the current url is as such.

    But what can I do to grab the about_us variable from that link?

    Is there a plugin that may enable something like the following example to work?

    {if page_url_segment_1 == "{segment_1}"}
      class="navon"
    {if:else}
      class="nav"
    {/if}
  • #2 / Jul 21, 2008 4:53pm

    Ingmar

    29245 posts

    I am not entirely clear what you are trying to achieve here, can you elaborate? Also, what is {exp:fetch_current_uri} I am not familiar with that plugin (?). Moving to Howto.

  • #3 / Jul 22, 2008 2:08am

    asozzi

    262 posts

    How about using the URL Segment Variables provided by EE?

  • #4 / Jul 22, 2008 5:48am

    Fusion Design

    128 posts

    Hi there,
    I will try to embellish a little, it’s just a little hard to explain.
    {exp:fetch_current_uri} is a plugin I obtained from here that outputs the exact url from your address bar.

    Basicly, when segment_1 of the current url is equal to about_us (as an example) I want to be able to say through a conditional to change the class of a link.

    {exp:weblog:entries category="3" dynamic="off" sort="asc"}
    {if current_page_url_segment_1 == "{segment_1}"}<a href="http://{page_url}" class="navon">{title}</a>
    
    {if:else}<a href="http://{page_url}" class="nav">{title}</a>
    {/if}
    {/exp:weblog:entries}

    If the code {current_page_url_segment_1} generated the segment_1 from the link it would work.

    Does that make any kind of sense?

  • #5 / Jul 22, 2008 6:21am

    Ingmar

    29245 posts

    Basicly, when segment_1 of the current url is equal to about_us (as an example) I want to be able to say through a conditional to change the class of a link.

    So, what exactly do you need a plugin for? Why not juse use:

    <a href="http://{page_url}" class="nav{if segment_1 == about_us}on{/if}">{title}</a>
    
  • #6 / Jul 22, 2008 6:57am

    Fusion Design

    128 posts

    No matter!
    I’ve found a way to do it.
    Hopefully by looking at this link You can see that I have to levels of sub navigation. (yes, a lot of things don’t look right with the template, it’s still being built!)

    For the first column I used:

    {if segment_2 == "{url_title}"}  class="leftnavon"{if:else}  class="leftnav"{/if}

    For the second column, I just used:

    {if segment_3 == "{url_title}"}  class="leftnavon"{if:else}  class="leftnav"{/if}

    Who know, this code may help someone else.

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

ExpressionEngine News!

#eecms, #events, #releases