Boss Your Segments Around: Freebie, an ExpressionEngine Addon

Doug Avery, Former Senior Developer

Article Category: #Design & Content

Posted on

I love how flexible ExpressionEngine URLs are — by not strictly parsing URLs, EE lets us send users to /whatever/long/url/we/want/ and find our own clever uses for the URL segments. We use this technique a lot at Viget for returning entries or specific templates, but it’s also great for setting page states, like showing unpublished entries by tacking a /preview/ segment onto a link or using /success/ to throw a "Form submitted!" message.

I recently wrote about Structure and how it gives clients more power and designers more freedom by directly assigning templates to pages. I also mentioned that it parses URLs strictly, which makes a lot of our old tricks much, well, trickier. In 1.6, we used NSM Safe Segments to 'hide' some segments from Structure and get around this issue, but the solution was less than ideal, and the upgrade to 2.0 found us searching for a new method.

Announcing Freebie

We made a wishlist of features we always wanted to see in Safe Segments, and the result is Freebie. Freebie prevents EE from parsing particular segments of your choosing, allowing you to use much more complex URLs without the risk of Structure choking on them.

Features

Wildcard segment names
'page-*' will match and ignore segments like "page-1" and "page-20"

'Breaking' segments
Set "blog" as a breaking segment, and EE will ignore all segments after it

Breaking on category segments
Freebie will (optionally) keep EE from parsing your 'category URL indicator' and any segments after it

Ignore numeric segments
Freebie can automatically ignore segments like "2010", "10", etc.

Access both original and parsed segments
Ignored segments are saved as their own {freebie_1}, {freebie_2} variables, while the segments EE actually parses will still be at {segment_1}, {segment_2}.

Match against any segment
Check to see if any URL segment matches a string, using the {exp:freebie:any} tag.

Freebie is pretty new, so I'm interested in hearing what feature ideas the community comes up with. Free free to submit any issues or requests on GitHub or in the comments.

Download & Learn More

Download and read more documentation from Devot:ee or GitHub.

Viget loves you!

In case you missed it, here's some more free downloads from the Viget design/front-end team:

Related Articles