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.

targeting url segments

July 02, 2007 1:33pm

Subscribe [1]
  • #1 / Jul 02, 2007 1:33pm

    open-box

    11 posts

    Hi there,

    i’m trying to this

    <div 
    {if segment_1 == "services"}
           id="content-services"
    {/if}
    
    >

    Which works fine.

    But inside the template group ‘services’ i have another template called ‘solutions’

    so the url segment is

    websitename.com/index.php/services/solutions/

    so for this second url segment, i want to target it through this code:

    <div
    {if segment_2 == "solutions"}
              id="content-solutions"
    {/if}

    but instead, now because i’m targeting both segments, the second one returns the following

    <div id="content-services" id="content-solutions">

    Basically both ID’s because i’m targeting both.

    But for segment 2 i only want to target it for the segment_2 and leave segment_1 out of it.

    I understand why it’s happening, but i can’t think of a way to stop it from happening.

    Any ideas?

    Thanks in advance.

  • #2 / Jul 02, 2007 3:10pm

    Lisa Wess

    20502 posts

    Did you ever consider just using the segment *as* your CSS class, rather than using conditionals?  class=“segment_2” etc?

    Using your way you’re going to need complex conditionals and to test for things a lot more robustly. In any case, this is more of a how-to so I’m going to move it up to that forum.

  • #3 / Jul 02, 2007 3:59pm

    open-box

    11 posts

    Thanks for the reply.

    I don’t understand what you mean by using the segment as a CSS class?

    Can you give me an example please?

  • #4 / Jul 02, 2007 4:24pm

    Lisa Wess

    20502 posts

    Sure, how about:

    <div id="{segment_2}">
    code
    </div>

    And then in your CSS, just create classes that would match those segments. =)  So if {segment_2} is desks, you would have

    #desks {};

    Hope that helps =)

  • #5 / Jul 02, 2007 4:59pm

    open-box

    11 posts

    i didnt know you could do that,

    that is so easy, thankyou.

  • #6 / Jul 02, 2007 5:15pm

    Lisa Wess

    20502 posts

    Well, think of it this way.  If you can evaluate it in a conditional, you can use it directly. As a matter of fact, when troubleshooting conditionals it can be important to out output the variable directly to ensure that you are testing against the correct thing.

    Does that make sense?

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

ExpressionEngine News!

#eecms, #events, #releases