[Zope] Render a string as tal

Alan Warren awarren.pub at gmail.com
Fri Nov 18 11:05:19 EST 2005


On 11/18/05, Chris Withers <chris at simplistix.co.uk> wrote:
> Alan Warren wrote:
> > single image into a folder.  So, I have a folder called view.  When an
> > image is viewed the URL looks like
> > /some_album/some_pic.jpg/view/?display=large
> >
> > The code looks like this:
> > <span tal:define="imgName python:request['URL2'][len(request['URL3']+1:]">
> >     <span tal:define="global imgObj python:path('here/'+imgName)"></span>
> > </span>
>
> ouch.

Thanks.
>
> This is really contorted. Why do you use URL2 and URL3?

To extract just the id of the image being viewed.  The relative path
from the template that presents the image to the image being presented
will always match that pattern.

>
> Is imgObj not just 'here' anyway?
Not in a manner I could easily work with, view is a folder containing
index_html (the page template in question), and a handful of other
page templates and scripts -- all of which are specific actions a user
may wish to perform on a single image -- rather than on a whole album.

Given the scenario I've outlined, do you have another suggestion?
I agree this isn't aesthetically pleasing, but to me it was quite intuitive.

>
> What is the page template where this code comes from called?
/view/index_html

>
> Why do you do a global define?
Because I'm godless.

>
> Why two define statements instead of just one?
So as to not post a massively long line of code to the list that would
be even more spaghetti like.  If it makes you feel any better the
actual code is more in the form:
<div tal:define="long_line here">
<!-- code that works on imgObj properties, -->
</div>

The question I was trying to answer wasn't about some coding style
issue, but rather about how to convert a string path to an object at
run-time.  I included the URL manipulation as an illustration of when
I had to use the path method.

Cheers,
Alan


More information about the Zope mailing list