We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

New extension: Last segment

Development and Programming

TonyNibbles's avatar
TonyNibbles
98 posts
16 years ago
TonyNibbles's avatar TonyNibbles

This simple little extension creates a new global variable which renders the fetches the current last segment in a URL.

The addition of a {last_segment} variable can be extremely useful for a number of reasons. The main benefit is that it allows you to create the appearance of sub-templates and hierarchical page structures.

For example, you could have a ‘pages’ weblog and by setting the url_title parameter of the weblog:entries tag to {last_segment}, create a structure of: /head/shoulders/knees/toes/

Download and details available here

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Hi Tony,

Nice little extension well done and thanks for sharing. Reminds me of the plugin I made a while back although a global variable is a great addition.

Best wishes,

Mark

       
Cocoaholic's avatar
Cocoaholic
445 posts
16 years ago
Cocoaholic's avatar Cocoaholic

Nice one Tony!

I have been using something very similar myself and ‘translated’ to your extension it looks like this: (shortest version I could come up with)

function set_last_segment()
{
    global $IN;
    $IN->global_vars['last_segment'] = end($IN->SEGS);
}

Your extension seems to also list ‘index.php’ as a last segment, the code above does not.

Cheers, Elwin

       
TonyNibbles's avatar
TonyNibbles
98 posts
16 years ago
TonyNibbles's avatar TonyNibbles

I’m clearly not that l33t with php but that looks pretty fricking l33t.

Nice one, will update soon 😊

       
Low's avatar
Low
407 posts
16 years ago
Low's avatar Low

Cool. I use a path.php variable which has the same result.

       
eyevariety's avatar
eyevariety
158 posts
16 years ago
eyevariety's avatar eyevariety

Its the battle of the last segments

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.