Problems, need help? Have a tip or advice? Post it here.
5 posts Page 1 of 1
Hi again!

I'm finally working on some custom routes and I ran into the following "problem":

If I masquerade the routable template (same approach as in the documentations, with page_views, edit_views etc etc) it won't recognize the edit, create and delete view, since with the masquerade option enabled a slash gets automatically added at the end of the url. Of course I can define the route accordingly:
Code: Select all
<cms:route name='create_view' path='create/' filters='authenticated' />

and everything works fine, but it simply doesn't "look good" if you know what I mean ;). Any thoughts on this or should I simply add the slash in the routes and leave it be?
Hi Klaus,

Can you please try defining the slash as optional like the following?-
<cms:route name='create_view' path='create/?' filters='authenticated' />

Does that help?
On the one hand defining the slash as optional makes it work in both cases, normal and masqueraded. On the other every route_link now looks like this "whatever.com/create/?"... maybe I'll erase the question mark which will then only work while masqueraded, but I would have "nicer" urls with the route_links... "whatever.com/create" would of course be the best option, but I guess this won't work while masqueraded right?
I should have seen that problem, Klaus - it is mentioned in the docs (http://www.couchcms.com/docs/custom-routes/) that fudging regex directly in the 'path' can lead to confusion. The proper way of tweaking the regex is through the cms:route_constraints child tag.

I think if we change the route definition to the following, it should make the closing trailing slash optional -
Code: Select all
<cms:route name='create_view' path='create{:slash}' filters='authenticated' >
    <cms:route_constraints
        slash='(\/?)'
    />
</cms:route>

While generating the link, you'll now need to provide the cms:route_link with the 'slash' value (empty as you'd like it to be) -
Code: Select all
<a href="<cms:route_link 'create_view' rt_slash='' />" class="button">New note</a>

I think the changes above should help. Please let me know.

In closing, I must admit that I hadn't tested custom-routes with masquerading at all. It is likely that you'll discover more problems using the two together. Keep me posted.
Thanks again! I'll let you know as soon as I ran into some new troubles :)
5 posts Page 1 of 1