Tell EE to ignore certain segments when routing. Put useful segments into your URI without getting 404s, bad templates, or messing up the routing Structure uses.
Freebie is built to run in ExpressionEngine 2.0, and will 100% fail in anything lower. To install:
- Copy freebie into your /system/expressionengine/third_party/ directory.
- Go to Add-ons → Extensions and “Enable extension.”
Caveat: If you’re using Freebie to ignore segments at the root level (mydomain.com/ignoredsegment/blog), you have to take special care when using the NSM htaccess generator, or any htaccess scheme that uses the “include” method of index.php removal.
Inside a template, you can access the original, un-effed-with URL segments using {freebie_1}, {freebie_2}
, etc. These will return the segments you see in your browser’s location bar — however, if you use {segment_1}
instead, you’ll get back the segments EE is actually parsing. For example, if you set “preview” and “comments” as Freebie segments, and visit…
/blog/preview/my-favorite-post/comments/
…your template vars will return the following:
{segment_1} == blog
{segment_2} == my-favorite-post
{freebie_1} == blog
{freebie_2} == preview
{freebie_3} == my-favorite-post
{freebie_4} == comments
Use {exp:freebie:any name="segment_name"} to see if any segment matches the “name” string. Example:
/blog/preview/my-favorite-post/comments/
{exp:freebie:any name="blog"} == "true"
{if "{exp:freebie:any name="comments"}" == "true"}<h2>Show comments</h2>{/if}
Use {exp:freebie:is_number segment="3"} to see if a segment is numeric or not. This is useful when you’re ignoring numeric segments, but want to test for their presence.
{exp:freebie:is_number segment="3"}
Use {exp:freebie:category_id segment="3"} to get the category_id of a segment. Useful in a number of ways. {exp:freebie:category_name segment="3"} will return the name of the category, and similar requests for category_description and category_image will do the same.
If you want to specify a group and/or site ID to pull the category from, use the following syntax: {exp:freebie:category_id segment=“3” group_id=“2” site_id="1"}
NOTE: You WILL NOT be able to use this tag directly in the category parameter of a channel:entries tag (I know, it sucks). Instead, try embedding the channel:entries loop and passing the category ID in.
preview|success|error
preview
success
error
march|april|may|ju*|august
The wildcard in ju*
means that both june
and july
will be freebie segments.
You can set an option to automatically ignore all number-only segments – this is useful for using urls like blog/2010/20/ in Structure.
Break segments are entered just like Freebie segments, but instead of being ignored, break segments tell EE to ignore all following segments. Example: You’re working in Structure, and want to use author urls and dates to control a blog, like so: /blog/lucille/2010/10. If you set “blog” as a break segment, you can throw whatever you want into the URI after this point without it affecting the template or page routing.
If you set this option, Freebie will automatically ignore your category URL indicator and any segments past it.
Freebie isn’t very subtle, so sometimes it can screw with existing EE functionality or plugins (especially when you set it to ignore numeric segments). That’s why there’s ‘Always Parse’, which acts like an override, telling Freebie to stop messing with this segment and any segments after it. This is especially useful with ‘search’ templates.
I only made this extension after using Leevi Graham’s NSM Safe Segments for a loooong time and missing it dearly in EE 2.0. Once I got started, I just kept adding features that we’ve had a need for at Viget from time to time.