Type: Extension
This little extension creates a new global variable which fetches the current last segment in a URL and registers it as a global variable.
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/
The extension also sets global variables for the last segment but ignoring pagination in the URL, and a variable for returning the current URL.
Requirements
- Tested on Expression Engine 1.6.7 and greater (should work with lower versions...)
Installation
To install Last segment, you must:
- First, copy the files to your Expression Engine installation. The zip archive is organised so that you can copy the files directly to the root of a 'regular' EE installation.
- Login to your Expression Engine control panel and navigate to extensions page. From here, click 'enable' next to the Last segment extension.
- And you're done!
Example
Simple!
{last_segment} {last_segment_np} {current_url}
If you'd like to send me beer money in exchange for updates and more modules, please do!
It'll be a Leffe or Hoegarrden by the way ;)
Version 1.0.2
4th December 2009
- Added new global variable last_segment_np. This ignores any pagination segments in the URL and returns the last segment before them.
- Added new global variable current_url. Returns the current URL.
Version 1.0.1
15th July 2009
- Added much shorter, l33t PHP code courtesy of Cocoaholic. Thanks!
Version 1.0.0
15th July 2009
- Initial release.