Creating a namespace
Hello everyone, I want to make my own name space with the following situation: class X: attributes = {'foo': 'bar'} x = X() Then I want to use it like that: <dtml-with x> <dtml-var foo> </dtml-with> The result should be : bar I found out that I have to somehow use TemplateDict and InstanceDict, but I have no clue how to use it....Of course there is no documentation on any web site or in the Zope code itself.... Thanks for you help!!! Regards, stephan -- Stephan Richter CBU - Physics and Chemistry Student Web2k - Web Design/Development & Technical Project Management
Stephan Richter wrote:
Hello everyone,
I want to make my own name space with the following situation:
class X:
attributes = {'foo': 'bar'}
x = X()
Then I want to use it like that:
<dtml-with x> <dtml-var foo> </dtml-with>
The result should be : bar
If you use <dtml-with x mapping> <dtml-var foo> </dtml-with> You will get the result you want. For the other stuff, look in DocumentTemplate/pDocumentTemplate.py. The python code is pretty clear, although the C version is what is normally used in Zope. Otherwise, see DocumentTemplate/DT_Util.py and DT_With.py, or see how it is done in ZPatterns in Expressions.py. By the way, I notice you posted this to zope@zope.org and zope-dev@zope.org. If you look in the standard footer of each email from both lists, you'll see this: ** No cross posts or HTML encoding! ** -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
Stephan,
** No cross posts or HTML encoding! ** ^^^^^^^^^^^^^^ Don't cross-post questions like this to both lists, especially when you're explicitly asked not to... ...leave the cross-posting to Brian, he usually has a good reason ;-)
Stephan Richter wrote:
I found out that I have to somehow use TemplateDict and InstanceDict, but I have no clue how to use it....Of course there is no documentation on any web site or in the Zope code itself....
I suggest you read: http://www.zope.org/Members/htrd/howto/FunctionTemplate ...and search the list archives. Maybe also ready about _.namespace on Page 39 of the old DTML reference. cheers, Chris
** No cross posts or HTML encoding! **
Ok, ok, I got the point.
I suggest you read: http://www.zope.org/Members/htrd/howto/FunctionTemplate
I did that already. It makes some sense, but not too much...similar code is in DT_With.py and DT_Util.py both of which I studied before posting to the list. I found out that I have to do something in my __call__ method of the class. I think the main problem is that 1) The variables names are horribly chosen, so that nothing makes much sense 2) No documentation whether inside the py files or any other documents Chris, I read even your little Wiki on TemplateDict and InstanceDict, but noone replied to your question! The only thing I haven't done was checking the Expressions.py of ZPatterns (I just tried to find the answer using ZClasses PY files) I will also read the pDocumentTemplate.py file.
...and search the list archives.
The e-groups search is pointless and never gives you anything useful (I did that already).
Maybe also ready about _.namespace on Page 39 of the old DTML reference.
I will do that. Thanks so much for your hints, but I am just a little frustrated right now (not because of you), since some of the Zope code looks like a hack. I could live without documentation, if the code would be some sort of readable. Regards, Stephan -- Stephan Richter CBU - Physics and Chemistry Student Web2k - Web Design/Development & Technical Project Management
Stephan Richter wrote:
...and search the list archives.
The e-groups search is pointless and never gives you anything useful (I did that already).
So use the ones at NIP: http://zope.nipltd.com/public/lists.html
Thanks so much for your hints, but I am just a little frustrated right now (not because of you), since some of the Zope code looks like a hack. I could live without documentation, if the code would be some sort of readable.
Well, maybe if you explained exactly what you're trying to do, we could be more helpful ;-) cheers, Chris
participants (3)
-
Chris Withers -
Stephan Richter -
Steve Alexander