Can someone provide an example of passing parameters using DTML? I'm sure this must be doable, but don't see an example in the Zope Book. I assume it would go something like <dtml-var var1 parm1 parm2> but how would var1 pick up parm1 parm2? -- John
Am Freitag, den 17.06.2005, 09:44 +0100 schrieb John Poltorak:
Can someone provide an example of passing parameters using DTML?
I'm sure this must be doable, but don't see an example in the Zope Book.
I assume it would go something like
<dtml-var var1 parm1 parm2>
but how would var1 pick up parm1 parm2?
Not at all. You could either have tried it out ;) Or looked at the DTML documentation in the Zope book *wink* ;) <dtml-var expr="somemethod(parm1=value1,parm2=value2)"> If you are learning anyway, why not skip the DTML part for now and go strait python-scripts and ZPT? -- Tino Wildenhain <tino@wildenhain.de>
Tino Wildenhain wrote at 2005-6-17 10:57 +0200:
... Not at all. You could either have tried it out ;) Or looked at the DTML documentation in the Zope book *wink* ;)
<dtml-var expr="somemethod(parm1=value1,parm2=value2)">
Be warned: this is likely to cause loss of the namespace. Do not forget to pass the two positional arguments (usually as "None, _"). They are essential. For more details, read "Calling DTML Objects" of <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html> -- Dieter
Am Freitag, den 17.06.2005, 19:09 +0200 schrieb Dieter Maurer:
Tino Wildenhain wrote at 2005-6-17 10:57 +0200:
... Not at all. You could either have tried it out ;) Or looked at the DTML documentation in the Zope book *wink* ;)
<dtml-var expr="somemethod(parm1=value1,parm2=value2)">
Be warned: this is likely to cause loss of the namespace. Do not forget to pass the two positional arguments (usually as "None, _"). They are essential.
For more details, read "Calling DTML Objects" of
<http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html>
Thanks Dieter, I must confess I was just too lazy to show all the pitfalls, assuming John takes the hint and reads the docs again *wink* ;)
On Fri, Jun 17, 2005 at 07:09:04PM +0200, Dieter Maurer wrote:
Tino Wildenhain wrote at 2005-6-17 10:57 +0200:
... Not at all. You could either have tried it out ;) Or looked at the DTML documentation in the Zope book *wink* ;)
<dtml-var expr="somemethod(parm1=value1,parm2=value2)">
Be warned: this is likely to cause loss of the namespace. Do not forget to pass the two positional arguments (usually as "None, _"). They are essential.
For more details, read "Calling DTML Objects" of
<http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html>
That looks useful. Is there also something which explains how to call ZPTs from a DTML object? I'm unable to pick up a passed parameter. This is what I've conjured up:- python:here.lib.parse_file(file=context.options['parm'],sepr=',',clone=1)"> hoping that "options['parm']" would get resolved as "ABC" but it doesn't. Any ideas?
-- Dieter
-- John
On Fri, Jun 17, 2005 at 09:31:44PM +0200, Andreas Jung wrote:
--On 17. Juni 2005 20:24:23 +0100 John Poltorak <jp@warpix.org> wrote:
Is there also something which explains how to call ZPTs from a DTML object?
Do you have a good reason for mixing ZPT and DTML?
Yes. I have a routine which works, but currently is uses a hard coded object names so I need to have lots of similar objects. I'm just trying to create something generic to simplify things. It's taken me several weeks to get this far and I don't feel like scrapping everything and spending a few months learning something entirely different which only gurus can handle.
-aj
-- John
On Fri, Jun 17, 2005 at 08:24:23PM +0100, John Poltorak wrote:
Is there also something which explains how to call ZPTs from a DTML object?
I'm unable to pick up a passed parameter.
This is what I've conjured up:-
python:here.lib.parse_file(file=context.options['parm'],sepr=',',clone=1)">
hoping that "options['parm']" would get resolved as "ABC" but it doesn't.
John, please, *always* provide tracebacks instead of saying things like "it doesn't".
Any ideas?
Without a traceback, everything I say below is guesswork. I'm assuming the above line comes from a page template. You neglected to mention what the calling DTML looks like, but I *guess* that it was something like this: <dtml-var "some_template(parm='ABC')"> yes? no? I am pretty sure that your problem is with the expression context.options['parm']. Why do I say this? Hint 1: Look at that expression from left to right. Hint 2: Think about what "context.options" means. In general, if you have not, you really should read the whole of http://www.plope.com/Books/2_7Edition/BasicScripting.stx and http://www.plope.com/Books/2_7Edition/ScriptingZope.stx ... not just once but several times :-) Taken together, they answer all "how to call X from Y" questions. -- Paul Winkler http://www.slinkp.com
On Fri, Jun 17, 2005 at 05:07:32PM -0400, Paul Winkler wrote:
On Fri, Jun 17, 2005 at 08:24:23PM +0100, John Poltorak wrote:
Is there also something which explains how to call ZPTs from a DTML object?
I'm unable to pick up a passed parameter.
This is what I've conjured up:-
python:here.lib.parse_file(file=context.options['parm'],sepr=',',clone=1)">
hoping that "options['parm']" would get resolved as "ABC" but it doesn't.
John, please, *always* provide tracebacks instead of saying things like "it doesn't".
Any ideas?
Without a traceback, everything I say below is guesswork.
I'm assuming the above line comes from a page template. You neglected to mention what the calling DTML looks like, but I *guess* that it was something like this: <dtml-var "some_template(parm='ABC')"> yes? no?
This is what I have:- <dtml-var expr="testlist(parm='myobjectname')"> I wish to get 'myobjectname' into this line in 'testlist' which is marked with ********* python:here.parse_file(file=context.******,sepr=',',clone=1)"> There must be a simple way of doing this, but I haven't come across an example of it and I've spent most of the day on it.
I am pretty sure that your problem is with the expression context.options['parm']. Why do I say this? Hint 1: Look at that expression from left to right. Hint 2: Think about what "context.options" means.
In general, if you have not, you really should read the whole of http://www.plope.com/Books/2_7Edition/BasicScripting.stx and http://www.plope.com/Books/2_7Edition/ScriptingZope.stx ... not just once but several times :-)
There is too much to read and understand. Much of it only ever makes any sense in retrospect. Manuals are not a very useful way of learning how to do something
Taken together, they answer all "how to call X from Y" questions.
I'm sure they do, if you can make any sense of it.
--
Paul Winkler http://www.slinkp.com
-- John
John Poltorak wrote:
On Fri, Jun 17, 2005 at 05:07:32PM -0400, Paul Winkler wrote:
On Fri, Jun 17, 2005 at 08:24:23PM +0100, John Poltorak wrote:
Is there also something which explains how to call ZPTs from a DTML object?
I'm unable to pick up a passed parameter.
This is what I've conjured up:-
python:here.lib.parse_file(file=context.options['parm'],sepr=',',clone=1)">
hoping that "options['parm']" would get resolved as "ABC" but it doesn't.
John, please, *always* provide tracebacks instead of saying things like "it doesn't".
Any ideas?
Without a traceback, everything I say below is guesswork.
I'm assuming the above line comes from a page template. You neglected to mention what the calling DTML looks like, but I *guess* that it was something like this: <dtml-var "some_template(parm='ABC')"> yes? no?
This is what I have:-
<dtml-var expr="testlist(parm='myobjectname')">
I wish to get 'myobjectname' into this line in 'testlist' which is marked with *********
python:here.parse_file(file=context.******,sepr=',',clone=1)">
There must be a simple way of doing this, but I haven't come across an example of it and I've spent most of the day on it.
Taking the options from my previous email and putting them together, you can say:: python:here.parse_file(file=getattr(context,options.parm),...) to get the attribute on the current context named 'myobjectname' or whatever else you provide as the 'parm' parameter on 'testlist'. The ellipsis is just to eliminate elements unnecessary to the point. --jcc -- "Building Websites with Plone" http://plonebook.packtpub.com/ Enfold Systems, LLC http://www.enfoldsystems.com
On Fri, Jun 17, 2005 at 05:39:23PM -0500, J Cameron Cooper wrote:
I'm assuming the above line comes from a page template. You neglected to mention what the calling DTML looks like, but I *guess* that it was something like this: <dtml-var "some_template(parm='ABC')"> yes? no?
This is what I have:-
<dtml-var expr="testlist(parm='myobjectname')">
I wish to get 'myobjectname' into this line in 'testlist' which is marked with *********
python:here.parse_file(file=context.******,sepr=',',clone=1)">
There must be a simple way of doing this, but I haven't come across an example of it and I've spent most of the day on it.
Taking the options from my previous email and putting them together, you can say::
python:here.parse_file(file=getattr(context,options.parm),...)
to get the attribute on the current context named 'myobjectname' or whatever else you provide as the 'parm' parameter on 'testlist'.
Many thanks. I appreciate the help. I think I've incorporated your suggestion into the code below... <html> <body> <span tal:define="opts python:here.parse_file(file=getattr(context,options.parm),sepr=',',clone=1)"> <tal:block repeat="opt opts"> <li><a tal:content="python:opt[1]" tal:attributes="href python:opt[0]"></a></li> </tal:block> </span> </body> </html> Unfortunately, when I try to use this expression <dtml-var expr="testlist(parm='links')"> I get this Zope error:- Error Type: AttributeError Error Value: 'dict' object has no attribute 'parm' Can't help thinking it is a simple syntax error - missing bracker, quote etc... but just can't figure it out.
--jcc
-- "Building Websites with Plone" http://plonebook.packtpub.com/
Enfold Systems, LLC http://www.enfoldsystems.com
-- John
On Fri, Jun 17, 2005 at 11:25:30PM +0100, John Poltorak wrote:
This is what I have:-
<dtml-var expr="testlist(parm='myobjectname')">
I wish to get 'myobjectname' into this line in 'testlist' which is marked with *********
python:here.parse_file(file=context.******,sepr=',',clone=1)">
There must be a simple way of doing this, but I haven't come across an example of it and I've spent most of the day on it.
OK, I repeat my earlier suggestion:
Hint 1: Look at that expression from left to right. Hint 2: Think about what "context.options" means.
Here's another clue: You are not really having a DTML problem. You are not really having a ZPT problem. You are not even really having a Zope problem. You are having a python problem. The problem is: given an object, foo, and an arbitrary string that identifies an attribute of foo, how do you get at that attribute? There is a built-in python function that exists for exactly this purpose. Read about the getattr() function here: http://python.org/doc/2.3.5/lib/built-in-funcs.html
In general, if you have not, you really should read the whole of http://www.plope.com/Books/2_7Edition/BasicScripting.stx and http://www.plope.com/Books/2_7Edition/ScriptingZope.stx ... not just once but several times :-)
There is too much to read and understand. Much of it only ever makes any sense in retrospect. Manuals are not a very useful way of learning how to do something
(resists urge to rant) Look - it doesn't have to all make sense on the first read, but eventually it starts to click. If you won't even read it at all, you're screwed before you begin. -- Paul Winkler http://www.slinkp.com
participants (6)
-
Andreas Jung -
Dieter Maurer -
J Cameron Cooper -
John Poltorak -
Paul Winkler -
Tino Wildenhain