Hello everybody,
I have some issues understanding the best practices of URL generation when
implementing resource lookup using Traversal in Pyramid. My web application
has a simple menu that is available on every page via Mako template
inheritance. In the older Pylons version with URL dispatch, I had this
h.url_for(controller=<something>, action=<something else>) method to help
me generate the right URL for the specific controller and action, no matter
where this was called. Now I am trying to port this application to
Traversal to simplify some things (mainly recursive resources like
categories containing categories etc.). I've understood so far, that
request.resource_url(request.context) will give me the correct URL for the
current context resource and the same thing using request.root as a
parameter will return my root URL. BUT: assume I have the following
structure:
root +-- entry1
+-- entry2 -- subentry
+-- entry3
I want to have the 3 entries in some kind of "main menu" on every page. How
do I - for example - get the URLs of entry1 and entry3 while currently
rendering the template for subentry (i.e. only having root, entry2 and
subentry available as resource objects)? Of course I could look up the root
resource and then simply append "entry1" etc. But this somehow "feels"
wrong, like glueing together the URLs by hand. And this would fail if root
was relocated into some sub-tree of a larger application as (presumably)
the "real" root would be something else (although I have to admit, that I
didn't read up on virtual roots yet, so excuse me if this is a totally
stupid question).
(On a side note: is there a standard way of accessing the request object in
the template? For now I just hand it over using a named parameter in the
view.)
Thanks for your patience and all the usual seasonal greetings,
Markus
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/pylons-discuss/-/Tk4pAMO_R1EJ.
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.