Skip to content

Instantly share code, notes, and snippets.

@siebird
Created October 3, 2012 01:40
Show Gist options
  • Save siebird/3824429 to your computer and use it in GitHub Desktop.
Save siebird/3824429 to your computer and use it in GitHub Desktop.
Use case of adding {last_segment_category_url_title}
<!-- Using @litzinger URL Helper plugin I added a new variable:
{last_segment_category_url_title}
This parses only if the last segment is a valid category (see case 3). I need this variable b/c {segment_3} will always parse, thus the third case returns true every time.
{all_segments} is perfect for the switchee variable b/c it's dynamic rather than hard coded: {segment_1}/{segment_2}/{segment_3}/{segment_4}
ie.
/products/
/products/cat
/products/cat/entry
/products/cat/subcat
/products/cat/subcat/entry
-->
{exp:switchee variable="{all_segments}" parse="inward"}
{case value="{segment_1}"}
<!-- if s1 is products and s2 is empty, show product home -->
{embed="products/_home"}
{/case}
{case value="{segment_1}/{segment_2}"}
<!-- if s2 is present, show category - all single products are either s3 or s4 -->
{embed="products/_cat" page_type="parent"}
{/case}
{case value="{segment_1}/{segment_2}/{last_segment_category_url_title}"}
<!-- if s3 is present and is a category -->
{embed="products/_cat" page_type="child"}
{/case}
{case default="yes"}
<!-- if s3 is an entry or s4 present, show single entry -->
{embed="products/_single"}
{/case}
{/exp:switchee}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment