named routes

25 views
Skip to first unread message

Matt DiDomenico

unread,
Jan 9, 2012, 10:18:12 PM1/9/12
to chica...@googlegroups.com
are named routes possible? and if so, is there a way to access them from templates? {{ Routes:lookup('login') }} or something to that extent?

thanks,
matt

Jose Luis Gordo Romero

unread,
Jan 10, 2012, 1:57:40 AM1/10/12
to chica...@googlegroups.com
Hi Matt,

Yes, Just updated the wiki the new unified syntax:


And for templates, you can use the {% url %} built-in custom tag, ex:

{% url controller="users" action="login" %}

--
Jose Luis Gordo Romero



2012/1/10 Matt DiDomenico <babso...@gmail.com>

Alex Marandon

unread,
Jan 10, 2012, 11:03:28 AM1/10/12
to chica...@googlegroups.com
On 10/01/12 07:57, Jose Luis Gordo Romero wrote:
Hi Matt,

Yes, Just updated the wiki the new unified syntax:


And for templates, you can use the {% url %} built-in custom tag, ex:

{% url controller="users" action="login" %}

I think what Matt means is referring to a route by an arbitrary name, so that you can change where it's implemented without changing your templates etc.

At the moment, I don't think it's possible.

Matt DiDomenico

unread,
Jan 10, 2012, 11:18:10 AM1/10/12
to chica...@googlegroups.com
Yea Alex, that's what I had in mind.  I just came over from a PHP framework (Silex) where each route can be named and then just {{ url('route_name') }} I was hoping something like this existed in CB.  Perhaps one could use comments to name the route in the controller and have that loaded up when the controller is initially compiled?

Alex Marandon

unread,
Jan 10, 2012, 12:24:07 PM1/10/12
to chica...@googlegroups.com
On 10/01/12 17:18, Matt DiDomenico wrote:
> Yea Alex, that's what I had in mind. I just came over from a PHP
> framework (Silex) where each route can be named and then just {{
> url('route_name') }} I was hoping something like this existed in CB.

Same with Django, which allows to define routes like this:

url(r'^archive/(\d{4})/$', archive, name="full-archive")

Then they be resolved from templates like this:

{% url full-archive 2007 %}

as documented at
https://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-patterns

In my experience this is useful when you override a function from a
reusable app, you just need to change URL configuration to point to your
own code but you don't need to modify any template that the reusable app
might provide or any inverse URL resolution it might do. It's a nice way
to decouple the application URL interface from its implementation.

Reply all
Reply to author
Forward
0 new messages