Skip to content

Instantly share code, notes, and snippets.

@siebird
Created November 16, 2012 17:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siebird/4089096 to your computer and use it in GitHub Desktop.
Save siebird/4089096 to your computer and use it in GitHub Desktop.
ExpressionEngine true nested URI's with Switchee, URL Helper & GW Has Children
// The key here is to use {all_segments} & {last_segment_category_url_title} from Litzinger's URL Helper extension.
// I fork'd it and added the {last_segment_category_url} to determine if the last segment is a cat or not.
// If {last_segment_category_url} is a category, it will parse and the case will run, if not, it defaults to single entry template
// {all_segments} variable is great b/c it's dynamically builds the rule, rather than a fixed variable="{seg_1}/{seg_2}/{seg_3}/{seg_4}"
// Controller Template.
{exp:switchee variable="{all_segments}" parse="inward"}
{case value="products"}
{embed="site/_product_cat" cat_seg="home"}
{/case}
{case value="{all_parent_segments}/{last_segment_category_url_title}"}
{embed="site/_product_cat"}
{/case}
{case default="yes"}
{embed="site/_product_entry"}
{/case}
{/exp:switchee}
// _product_cat template:
{exp:switchee variable="{embed:cat_seg}" parse="inward"}
{case value="home"}
product home page
{/case}
{case default="yes"}
{exp:gwcode_haschildren:check cat_id="{last_segment_category_id}"}
{if gwcode_haschildren}
category has child cats
{if:else}
show entries of last child cat
{/if}
{/case}
{/exp:switchee}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment