[Zope] Render a string as tal
Chris Withers
chris at simplistix.co.uk
Mon Nov 21 05:49:07 EST 2005
Alan Warren wrote:
> 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.
*cries*
>>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.
*sigh* I can see why you want this, but I'd loose the 'view' folder and
just have the methods somewhere acquirable...
in fact, I'd just rename your index_html to 'view'.
Then you can just replace all instances of imgObj with 'context'
>>Why do you do a global define?
>
> Because I'm godless.
huh?
> 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.
You should very rarely have to do this. If you end up doing this, big
alarm belsl should start ringing ;-)
cheers,
Chris
--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
More information about the Zope
mailing list