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.

Trying to wrap my head around URL's that are 4 levels deep...

April 13, 2012 11:34am

Subscribe [6]
  • #1 / Apr 13, 2012 11:34am

    5BYFIVE Creative

    159 posts

    I’m going to try and explain my problem so it makes sense…here we go…

    I’m looking to have a url structure like this for a specific section of the site…

    1. / investor_relations / corporate_governance / charters
    2. / investor_relations / corporate_governance / code_conduct
    3. / investor_relations / corporate_governance / executive_bios / john_doe

    / template_group / template / url_title

    The first two are not a problem, I would make a “Corporate Governance” channel and each entry would become a “page”.  “Charters” and “Code Conduct” would be entries. The “corporate_governance” template would have a conditional to display static page content if segment_3 is blank, and would display the channel content if segment 3 is not blank.

    The problem arrises when I need to go another level deep. In the third URL listed above the “Executive Bios” page would be a channel entry displayed as a static page. This would be fine if it was just some content. But I want to list the “Executive Bios” channel entries on this page…and then when one of those is clicked, I want to load a bio details page.

    /template_group/template/ ? /url_title

    I’m pretty much stuck. I’ve been reading TONS of information trying to figure this out. Categories were an option I found, but I don’t think that would work in my case and wouldn’t be user friendly for the client to create new pages.

    “Why don’t you use Structure?”, you might be asking. I would love to use Structure and think it would solve my problems here. But I also have to make a dedicated mobile version of this site and need to pull content from the main site to the mobile site. The way structure works would require me to rebuild a separate structure tree on the mobile site and enter in the information again. Having to update content twice is not an option.

    If you need me to explain something better please let me know. I’m getting desperate here, so any help would be amazing!

  • #2 / Apr 13, 2012 11:49am

    aelvan

    33 posts

    I’d use Switchee for this. Something like this:

    {exp:switchee variable = "{segment_3}" parse="inward"}
        
        {case value=""}
            segment_3 is blank, display the channel content.
        {/case}
        
        {case value="executive_bios"}
            ok, so we've got a "special" segment_3 to deal with.
    
            {switchee variable="{segment_4}" parse="inward"}
                {case value=""}
                    segment 4 is blank, so display all exec bios.
                {/case}
                {case default="Yes"}
                    segment 4 is not blank, display exec bio.
                {/case}
            {/switchee}
    
        {/case}
    
        ... add any other "special" url segments in seperate cases…
        
        {case  default="Yes"}
            Not blank and not "special". Must be an url_title…
        {/case}
     
    {/exp:switchee}

    You can download Switchee here: http://devot-ee.com/add-ons/switchee. Make sure you use version 2 since you need support for nesting.

    I guess you could solve this with normal {if} conditionals too, but that would be very inefficient, considering how EE handles them.

     

  • #3 / Apr 13, 2012 12:01pm

    jelle

    104 posts

    that would have been my reply, aelvan beat me to it

  • #4 / Apr 13, 2012 12:12pm

    5BYFIVE Creative

    159 posts

    aelvan, that definitely looks interesting. I’ve used Switchee before for something much simpler. I’ll have to give this a shot. Have guys done something like this before or are you just thinking it should work?

    Also, if this is a good solution, someone should make a blog post as a lot of people have problems with URL’s this deep. Could help a lot of people!

    Thank you!

  • #5 / Apr 13, 2012 12:22pm

    Natetronn

    161 posts

    Mike that was my recommendation on twitter as well and it should work fine. We’ll be waiting for your blog post once your done 😉

  • #6 / Apr 13, 2012 12:37pm

    aelvan

    33 posts

    Actually I’m working on a site right now where the url structure is almost completely separated from the actual EE template group/template structure. In my default template I’m doing something very similar to what I outlined above - works like a charm. 😊

    In my case, I needed to optimize the urls for SEO, so the url titles for items in the main channels, should be segment_1 when viewing them. Also, the items are organized in different types of categories and sorted differently. A simplified version of my current default template:

    {exp:switchee variable="{segment_1}" parse="inward"}
    
      {case value=""}
        {!-- display frontpage --}
      {/case}
    
      {case value="drinks"}
    
        {!-- display some kind of listing. check segment_2 --}
    
        {switchee variable="{segment_2}" parse="inward"}
          {case value="type"}
            {!-- display drinks with categories in type group --}
          {/case}
          {case value="ingredients"}
            {!-- display drinks with categories in ingredients group --}
          {/case}
          {case value="alphabetically"}
            {!-- display drinks sorted alphabetically --}
          {/case}
          {case value="popularity|"}
            {!-- display drinks sorted by popularity. this is also the default case if segment_2 is empty --}
          {/case}
          {case default="yes"}
            {!-- there is a segment_2, but it's not a trigger word. must be a category then. display drinks in this category --}
          {/case}
        {/switchee}
    
      {/case}
    
      {case default="Yes"}
        {!-- display one drink --}
      {/case}
    
    {/exp:switchee}

    Inside each case I’m embedding the correct templates. So, this gives me beautiful url’s like:

    http://domain/  <—frontpage
    http://domain/a-drink-url-title  <—one drink
    http://domain/drinks  <—lists drinks by popularity
    http://domain/drinks/alphabetically  <—lists drinks by name
    http://domain/drinks/type  <—lists drinks, and shows categories in category group type
    http://domain/drinks/ingredients  <—lists drinks, and shows categories in category group type
    http://domain/drinks/vodka  <—lists drinks in category vodka

    And so on and so forth. The complete site structure is more complex, but you get the idea. 😊

     

  • #7 / Apr 13, 2012 12:39pm

    jelle

    104 posts

    i’ve been using this approach for a few years, even before switchee existed (with plain conditionals) and it allways worked fine. switchee helps a lot on a performace level

  • #8 / Apr 16, 2012 11:54am

    Dan Decker

    7338 posts

    Hi Mike,

    It looks like you’ve gotten some solid advice from the Community here!

    Another solution would be to use embeds and pass segment_4 in as the url_title for the bio entry.

    {if segment_4}
     {emned="executive/bio" bio_title="{url_title}"}
    {if:else}
     Full list
    {/if}

    Is there anything else I can assist you with?

    Cheers,

  • #9 / Apr 16, 2012 12:11pm

    aelvan

    33 posts

    I don’t think that example is sufficient, Dan. In Mikes example, a missing {segment_4} could indicate either that he’s going to display the full executive biolist OR an article with url_title=={segment_3}.

  • #10 / Apr 18, 2012 4:56pm

    Shane Eckert

    7174 posts

    Hey MikeTheVike,

    It looks like you are set. Is there anything else we can help you with?

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases