[Zope] Re: How to do...[Rendering zpt on the fly]
garito at sistes.net
Sat Oct 28 09:36:16 EDT 2006
Josef Meile escribió:
> Hi Garito,
> I saw in another thread you still need this. If I'm not wrong what you
> are pretending is to somehow render zpt on the fly. So, here is my idea:
>> I would like to write things like:
>> object.property = 'here/anotherproperty'
>> object.anotherproperty = 'Barcelona'
>> and ask it like:
>> print object.property -> 'Barcelona'
>> <tal:city tal:replace='here/property' /> -> 'Barcelona'
>> Is this possible?
> I think you could perhaps create a new class to store the tal
> expression attributes, let's say you called it ExpressionAttribute.
> This class must be callable and be able to evaluate tal expressions.
> This is a small sketch of how I think it should look like:
> from Products.PageTemplates.ZopeTemplate import ZopeTemplate
> class ExpressionAttribute:
> #Here I also assume that you only enter the expressions
> #without html and the tal part, like: 'here/property'
> #Please also noticed that all sintax errors in your zpt
> #code must be catched somewhere
> def __init__(self, id, talExpr):
> self.talExpr = '<span tal:replace="%s"/>' % talExpr
> #I'm not sure about this, but I think it will create a Template on
> #the fly.
> self.zpt = ZopePageTemplate(id, text = self.talExpr)
> #Note: I really don't know if you have to pass other parameters to
> #pt_render, ie: the container of your property. You will have to test
> def __call__(self):
> return self.zpt.pt_render()
> Then, in the __init__ of your zope product you will need to do things
> like this:
> class YourProd(...):
> def __init__(self,prop1,prop2,prop3,...):
> #This is a normal property
> self.prop1 = prop1
> #This two are tal expression properties
> self.prop2 = ExpressionAttribute(prop1)
> self.prop3 = ExpressionAttribute(prop1)
> Then, I guess you can call it as:
> yourProdObj.prop3 or in tal: here/prop3
> I'm not sure about what I wrote and if this is what you are looking
> for. I just hope it helps.
> Zope maillist - Zope at zope.org
> ** No cross posts or HTML encoding! **
> (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
Thank you for your help but I think your aproach is a little complicate
I'm asking for this because it seems to be the simplest way (at least in
I prefer the new aproach I'm searching for (see "How to create a new TAL
But thank you so much for your idea!!!
More information about the Zope