On 6/11/07, voltron <[EMAIL PROTECTED]> wrote:
> On Jun 11, 9:42 pm, "Mike Orr" <[EMAIL PROTECTED]> wrote:
> > On 6/11/07, voltron <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> >
> >
> > > I have to "clean" and create a few links, for example, Cheese?
> >
> > > so I have this construct
> >
> > > <li><a href="${h.url_for(url.replace(' ', '_').replace('?',
> > > '').lower()) |trim}">${url}</a></li>
> >
> > > this, I thought is not scalebale and messey so I thought I could
> > > create a function for cleaning:
> >
> > > <%def name="clean_link(link)">
> > > ${link.replace(' ', '_').replace('?', '').replace('!', '').lower()}
> > > <% return link %>
> > > </%def>
> >
> > > <li><a href="${h.url_for(clean_link(url)) | trim}">${url}</a></li>
> >
> > > unfortunately, this does not produce the right links anymore with
> > > url_for(), it cleans the link, but all the subdirectories in the link
> > > are gone.
> >
> > > What would be the best way to go about this?
> >
> > How did the links get dirty in the first place? Do they come from an
> > external/legacy source? Or are you generating the dirty URLs to
> > display to the user? I normally name all my routes, then pass in the
> > arguments needed to recreate them:
> >
> > h.url_for("pizza", cheese=1, pepperoni=0)
> >
> > rather than passing in URLs. Why can you not do this?
>
> they are actually being recreated Mike
> example:
>
> g.links = ["home", "Who we are", "Test?"]
>
> <div id="menu">
> % for item in g.links:
> <a href="/${item.lower().replace(' ', '')}" title="${item}"
> class="level_menu">${item}</a><img src="img/menu_seperator.gif"
> alt="">
> % endfor
> </div>
>
Here's what I do in this case:
g.links = [("/home", "home"), ("/who", "Who we are"), ("/test", "Test?")
% for url, label in g.links:
<a href="${url}">${label}</a>
% endfor
I also have a h.link(label, *url_for_args, **url_for_kw) that does a
combination of h.url_for and h.link_to. This is useful to prevent
overly long template expressions.
--
Mike Orr <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---