[ZPT] forcing a string to be a path
Jean-Philippe Rey
jprey at ads.ecp.fr
Sat May 1 03:45:41 EDT 2004
Adam wrote:
> I am attempting to include different content based on a variable in the
> url, fish?content=trout. In my template doing something like:
>
> <span tal:replace="structure request/content">content goes here</span>
>
> ends up replacing the tag with the string "trout" instead of the
> contents of the file named trout. I thought I could work around this by
> forcing it to be interpreted as a path using path:request/content, but
> that didn't actually change anything. Is there a way to include a file
> based on a variable like this?
This works
<span tal:replace="structure python:here.restrictedTraverse(request.content)">
This should also work
<span tal:replace="structure python:path('here/' + request.content)">
With the first solution you won't have an error if your content doesn't exist.
Depending on what you want, you may use 'container' instead of 'here' in
the previous expressions.
--
Jean-Philippe Rey Professeur informatique - École Centrale Paris
jprey at ads.ecp.fr 92295 Châtenay-Malabry Cedex - France
More information about the ZPT
mailing list