Published by Mijingo

movie icon image

EE Insider Blog

Spend your time learning and developing sites with ExpressionEngine and we'll use this blog to keep you informed of all the news related to ExpressionEngine and CodeIgniter.

» Read more in the Archives.

» Have a tip? Send us your EE news.

Learn ExpressionEngine Today

Over a series of 8 videos, watch and learn as Ryan builds an entire ExpressionEngine website from beginning to end. Get started now.

New Extension: Last Segment

Tom Kiss published a new extension today that makes it very easy to get the last segment of the URL.

This 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/


Why use this when you can fetch the segment using {segment_x}? Well, because this way you can fetch the last segment without even knowing the segment number. This is handy for embedded templates that are shared across site templates and where the segment count will vary.

All in all, a handy extension that should help you make your templates even more reusable.

I briefly tested this extension in my local sandbox and it worked as expected. The extension is a free download and available now: Last Segment by Tom Kiss

Posted on Jul 15, 2009 by Ryan Irelan

Filed Under: EE Add-ons, EE Extensions