We are trying to use only TAL in our Zope documents. It's been frustrating in some ways. Is there a way in TAL to simply run a python function? We've been using the omit-tag to do this, but I find this cludgy. <div tal:omit-tag="python:foo()"></div> Are other people just using dmtl for this sort of thing. Is there a way to do it in TAL that isn't cludgy? John -
John Kipling Lewis wrote:
<div tal:omit-tag="python:foo()"></div>
Are other people just using dmtl for this sort of thing. Is there a way to do it in TAL that isn't cludgy?
No, not generally. Its considered poor form to be executing side-effects from presentation code. -- Jamie Heilman http://audible.transient.net/~jamie/ "We must be born with an intuition of mortality. Before we know the words for it, before we know there are words, out we come bloodied and squalling with the knowledge that for all the compasses in the world, there's only one direction, and time is its only measure." -Rosencrantz
simply run a python function? We've been using the omit-tag to do this, but I find this cludgy.
<div tal:omit-tag="python:foo()"></div>
Are other people just using dmtl for this sort of thing. Is
We use tal:define for this purpose: <body tal:define="dummy python:foo(); <other assignments>" ... Usually this way we run some page setup code which we put inside <body> or even top-level <html> tag. Regards, Dmitry
On Fri, 30 May 2003, Dmitry Dembinsky wrote:
We use tal:define for this purpose:
<body tal:define="dummy python:foo(); <other assignments>" ...
Usually this way we run some page setup code which we put inside <body> or even top-level <html> tag.
We have done this as well. It just seemed an obvious hole in the tal system. There should be a way to execute arbitrary code in tal. Something like: <body tal:run="python:foo()"> John -
On Fri, May 30, 2003 at 09:34:50AM -0400, John Kipling Lewis wrote:
On Fri, 30 May 2003, Dmitry Dembinsky wrote:
We use tal:define for this purpose:
<body tal:define="dummy python:foo(); <other assignments>" ...
Usually this way we run some page setup code which we put inside <body> or even top-level <html> tag.
We have done this as well. It just seemed an obvious hole in the tal system. There should be a way to execute arbitrary code in tal. Something like:
<body tal:run="python:foo()">
tal:define works perfectly well for this. I don't think we need a new tal statement just for the special case of not caring about the return value. -- Paul Winkler http://www.slinkp.com Look! Up in the sky! It's HYPER SKULL MAFIOSO! (random hero from isometric.spaceninja.com)
On Fri, 30 May 2003, Paul Winkler wrote:
On Fri, May 30, 2003 at 09:34:50AM -0400, John Kipling Lewis wrote:
On Fri, 30 May 2003, Dmitry Dembinsky wrote:
We use tal:define for this purpose:
<body tal:define="dummy python:foo(); <other assignments>" ...
Usually this way we run some page setup code which we put inside <body> or even top-level <html> tag.
We have done this as well. It just seemed an obvious hole in the tal system. There should be a way to execute arbitrary code in tal. Something like:
<body tal:run="python:foo()">
tal:define works perfectly well for this. I don't think we need a new tal statement just for the special case of not caring about the return value.
If define allow you to not "define" a variable then I would agree, but it's confusing for people looking at the code to define a variable and then never use it. For example: <body tal:define="foo python:foo()"> If foo() doesn't return anything, you've just defined a variable foo that doesn't do anything which will confuse anyone who is new to the code. I shouldn't have to define a variable just to run foo(). John -
On Fri, 30 May 2003, Paul Winkler wrote:
On Fri, May 30, 2003 at 09:34:50AM -0400, John Kipling Lewis wrote:
On Fri, 30 May 2003, Dmitry Dembinsky wrote:
We use tal:define for this purpose:
<body tal:define="dummy python:foo(); <other assignments>" ...
Usually this way we run some page setup code which we put inside <body> or even top-level <html> tag.
We have done this as well. It just seemed an obvious hole in the tal system. There should be a way to execute arbitrary code in tal. Something like:
<body tal:run="python:foo()">
tal:define works perfectly well for this. I don't think we need a new tal statement just for the special case of not caring about the return value.
If define allow you to not "define" a variable then I would agree, but it's confusing for people looking at the code to define a variable and then never use it. For example:
<body tal:define="foo python:foo()">
If foo() doesn't return anything, you've just defined a variable foo that doesn't do anything which will confuse anyone who is new to the code. I shouldn't have to define a variable just to run foo().
John -
John, I think you exaggarate regarding this "problem". It is simply resolved by naming unneeded return value "dummy" or "unused". This way it wouldn't confuse anyone looking at the code. IMHO, keeping tal simple is more important that providing nice-to-have features for easily avoidable situations. Just compare an effort that'd be required to implement a dedicated TAL attribute for running scripts with using ready and working solution you have in hand. Dmitry.
Other detail .. in the other posts in this thread, I see everyone using the python:foo() syntax. That can be shortened by using a path expression: <tal:foo define="dummy here/foo" /> or <span tal:define="dummy here/foo" /> depending on taste .. -- Jean Jordaan http://www.upfrontsystems.co.za
actually, it's not just a matter of style. simple path expressions also evaluate a tick faster. jens On Tuesday, Jun 3, 2003, at 10:36 US/Eastern, Jean Jordaan wrote:
Other detail .. in the other posts in this thread, I see everyone using the python:foo() syntax. That can be shortened by using a path expression:
<tal:foo define="dummy here/foo" />
or
<span tal:define="dummy here/foo" />
depending on taste ..
-- Jean Jordaan
Hi, John Kipling Lewis wrote:
On Fri, 30 May 2003, Dmitry Dembinsky wrote:
We use tal:define for this purpose:
<body tal:define="dummy python:foo(); <other assignments>" ...
Usually this way we run some page setup code which we put inside <body> or even top-level <html> tag.
We have done this as well. It just seemed an obvious hole in the tal system. There should be a way to execute arbitrary code in tal. Something like:
<body tal:run="python:foo()">
John -
I have to disagree whith this. Even tal:define is somewhat ugly. The design goal has to be to remove as much application code as possible from template. So always set up your data outside of the template. A handy way is to have a simply python script "dispatcher" method which calculates all values and stuff and then returns the actual template like this: -- python script -- contect.callSomething() val=context.calculateSomething() return context.Template(values=val) -- /python script-- in this example you can access values thru options/values in TAL. This is clean and handy. You even can return different templates according to a condition and set header information and so on. HTH Tino Wildenhain
Tino, probably an approach you offer better serves the logic/presentation separation, though it is not flawless as well. Of course, defining a bunch of variables in a page template using complicated expressions is an obvious misusing of ZPT. However, IMO, something like <span tal:define="item python:here/findItem('123')" tal:content="string:${item/getId}: ${item/title}">Id: Title</span> is more simple than using parametrized template and having "item" defined elsewhere. Not to mention that if I see smth like tal:content="options/values" in someone's code I have no clue where the "values" comes from and how it is calculated (unless the code is properly commented :) I think how you write the code is mostly a matter of taste. Usually, one will use his/her favorite method, not the one that is considered "best practice" by someone else - we're human beings, not machines :) e.g. there are people that don't understand what OOP is for, but still write great programs :) And definetly, there is no place here for the holy war, as John assumes. Call it an "intellectual duel" if you wish :) Best regards, Dmitry
Hi,
John Kipling Lewis wrote:
On Fri, 30 May 2003, Dmitry Dembinsky wrote:
We use tal:define for this purpose:
<body tal:define="dummy python:foo(); <other assignments>" ...
Usually this way we run some page setup code which we put inside <body> or even top-level <html> tag.
We have done this as well. It just seemed an obvious hole in the tal system. There should be a way to execute arbitrary code in tal. Something like:
<body tal:run="python:foo()">
John -
I have to disagree whith this. Even tal:define is somewhat ugly. The design goal has to be to remove as much application code as possible from template. So always set up your data outside of the template.
A handy way is to have a simply python script "dispatcher" method which calculates all values and stuff and then returns the actual template like this:
-- python script -- contect.callSomething() val=context.calculateSomething()
return context.Template(values=val) -- /python script--
in this example you can access values thru options/values in TAL. This is clean and handy. You even can return different templates according to a condition and set header information and so on.
HTH Tino Wildenhain
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
participants (7)
-
Dmitry Dembinsky -
Jamie Heilman -
Jean Jordaan -
Jens Vagelpohl -
John Kipling Lewis -
Paul Winkler -
Tino Wildenhain