I’m proud to present Slashee, an plugin that allows you to add/remove leading/trailing slashes to a string (primarily, URLS).
Written by Karl Swedberg: englishrules.com | karlswedberg.com with help from me, Tim Kelty: geniuscar.com …Karl did all the real work, though. We’re both happy employees at Fusionary.
So essentially it works like this:
{exp:slashee start="remove"}/path/to/file{/exp:slashee}
Result: path/to/file
{exp:slashee start="remove" end="remove"}/path/to/file{/exp:slashee}
Result: path/to/file
{exp:slashee start="add" end="remove"}path/to/file{/exp:slashee}
Result: /path/to/file
How I use this Sometimes a client may need to enter a link or path, and we don’t know if they are going to include leading or trailing slashes. If we use that field to assemble a URL at some point with other segments, we might end up with something like http://site.com//path/to/file, if we use Slashee, we always get the URLs how we want.
For example: I often have a “Miscellaneous Content” weblog, with a title and body field. In order for that content to be used in a site search, I also include an optional “Search URL path” field. That way in my search results template I can have a conditional that uses that field instead of an auto_path for items in the Miscellaneous Content weblog. I also display the url at the bottom by assembling something like {homepage}{misc_search_url_field}. I use Slashee to make sure we don’t get extra slashes in there, (http://site.com//path/to/file)
Simple but useful, for me anyway! Enjoy.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.