averyvery / freeway

Simple Routing for EE
43 stars 4 forks source link

When would I use freeway? #1

Closed ghost closed 12 years ago

ghost commented 13 years ago

I think I understand what this does but its not clear what its for?

What is the user scenario in which in one uses this?

When should this be used?

averyvery commented 13 years ago

Routing is kind of an abstract idea, and it's mostly valuable if you care about your URLs and have difficulty getting them the way you like in EE. A few examples of cases where routing matters:

Basically, routing will sometimes simplify your templates. It will mean fewer conditionals and fewer segment checks.

Freeway only contains half of a traditional "routes" system — the other half would be smart links that automatically update to match the routes. I don't think EE's structure is strict enough for a feature like this to work, but it might be worth thinking about.

ghost commented 13 years ago

"reuse one template for several URLs, without using lots of EE embeds and extra templates"

That one is making sense to me right now. Let me give it a shot

mildlygeeky commented 13 years ago

Looks really promising—when Freeway is installed does it override all URL routing, or can it work alongside the normal template_group/template URL handling in EE?

averyvery commented 13 years ago

Nope, Freeway doesn't take over anything if you don't tell it to. A Freeway route looks like this:

(pattern) => (destination)

Freeway checks all non-CP URLs against the "patterns" you enter (currently, it loops backwards through them from the end). If it finds a match, it routes the request to the "destination". If not, it doesn't. So, Freeway routes can exist alongside your normal templates — even alongside Structure URLs — without causing issues.

However, if you write a route that matches everything, it's bad news:

{{foo}} => bar

THAT route will seriously mess up your stuff, because {{tokens}} are basically wildcards.

ghost commented 12 years ago

Pardon my confusion...

The biggest issue I have with EE is working within template when there are more than 3 segments. I'm not quite grasping a way to use Freeway to route a third segment.

/resources/ (teamplage_group/index) /resources/installation/ (teamplage_group/template) /resources/installation/installation_detail_page (teamplage_group/template_detail)

As an example, what rule would I need to create to make the proper routing?

averyvery commented 12 years ago

Quick thing, indabagroup: I can't seem to reply to the email you sent me, because your email address is failing permanently. Feel free to email me again with a different reply address, or let me know if your mail server comes back up.

averyvery commented 12 years ago

That routing looks correct, basically. In Freeway syntax, it would be:

/resources/ => /template_group/
/resources/installation/ => /template_group/template/
/resources/installation/installation_detail_page/ => /template_group/template_detail/

This is, of course, a one-off solution for mapping ONLY installation and installation_detail to these specific URLs. For something more flexible, you could use:

/resources/ => /template_group/
/resources/{{resource}}/ => /template_group/template/{{resource}}
/resources/{{resource}}/{{page}}/ => /template_group/template_detail/{{resource}}/{{page}}/

On your actual templates, you would use the {freeway_3} and {freeway_4} variables to select the appropriate resource and subpage.