Hi All I am trying to execute a macro only if a condition is satisified. The code I am using is: <div tal:condition="python:request.form['id'] == 't' | nothing" metal:use-macro="container/zptmac_memtask/macros/zptmac_taskslist"> List </div> <div tal:condition="python:request.form['id'] == 'p' | nothing" metal:use-macro="container/zptmac_mempending/macros/zptmac_pendlist"> List </div> <div tal:condition="python:request.form['id'] == 'w' | nothing" metal:use-macro="container/zptmac_memweek/macros/zptmac_weeklist"> List </div> <div tal:condition="python:request.form['id'] == 'a' | nothing" metal:use-macro="container/zptmac_memall/macros/zptmac_alllist"> List </div> Depending on which value is passed with the form object i want that a particular macro be called. But as soon as this page is rendered it shows me all the macros irrespective of whether I am sending any value for "id". Is there some way I can check the condition and only show the required macro. I m sure someone working on this particular area dealing with different conditions can help me out. Best Regards John Kunchandy --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.381 / Virus Database: 214 - Release Date: 8/2/2002
i would *not* put both the tal:condition and metal:use-macro statements on a single tag. separate them so each is on its own tag:: <div tal:condition="python:request.form['id'] == 't' or nothing"> <metal:block use-macro="container/zptmac_memtask/macros/zptmac_taskslist"
List </metal:block> </div> jens On Tuesday, August 20, 2002, at 07:18 , zope wrote:
Hi All I am trying to execute a macro only if a condition is satisified. The code I am using is: <div tal:condition="python:request.form['id'] == 't' | nothing" metal:use-macro="container/zptmac_memtask/macros/zptmac_taskslist"> List </div> <div tal:condition="python:request.form['id'] == 'p' | nothing" metal:use-macro="container/zptmac_mempending/macros/zptmac_pendlist"> List </div> <div tal:condition="python:request.form['id'] == 'w' | nothing" metal:use-macro="container/zptmac_memweek/macros/zptmac_weeklist"> List </div> <div tal:condition="python:request.form['id'] == 'a' | nothing" metal:use-macro="container/zptmac_memall/macros/zptmac_alllist"> List </div> Depending on which value is passed with the form object i want that a particular macro be called. But as soon as this page is rendered it shows me all the macros irrespective of whether I am sending any value for "id". Is there some way I can check the condition and only show the required macro. I m sure someone working on this particular area dealing with different conditions can help me out. Best Regards John Kunchandy
How about: <div tal:define="macroName request/form/id"> <metal:block use-macro="container/zptmac_memtask/macros/?macroName"> List </metal:block> </div> Combined with renaming your "id" field in your forms (or your macro names, either will do) so they match? That munges the whole list of tal:conditions down to something more manageable... KJL On Tue, 2002-08-20 at 21:56, Jens Vagelpohl wrote:
i would *not* put both the tal:condition and metal:use-macro statements on a single tag. separate them so each is on its own tag::
<div tal:condition="python:request.form['id'] == 't' or nothing"> <metal:block use-macro="container/zptmac_memtask/macros/zptmac_taskslist"
List </metal:block> </div>
jens
On Tuesday, August 20, 2002, at 07:18 , zope wrote:
Hi All I am trying to execute a macro only if a condition is satisified. The code I am using is:
<div tal:condition="python:request.form['id'] == 't' | nothing" metal:use-macro="container/zptmac_memtask/macros/zptmac_taskslist"> List </div> <div tal:condition="python:request.form['id'] == 'p' | nothing" metal:use-macro="container/zptmac_mempending/macros/zptmac_pendlist"> List </div> <div tal:condition="python:request.form['id'] == 'w' | nothing" metal:use-macro="container/zptmac_memweek/macros/zptmac_weeklist"> List </div> <div tal:condition="python:request.form['id'] == 'a' | nothing" metal:use-macro="container/zptmac_memall/macros/zptmac_alllist"> List </div> Depending on which value is passed with the form object i want that a particular macro be called. But as soon as this page is rendered it shows me all the macros irrespective of whether I am sending any value for "id". Is there some way I can check the condition and only show the required macro. I m sure someone working on this particular area dealing with different conditions can help me out.
Best Regards
John Kunchandy
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
On Tue, 2002-08-20 at 22:03, KevinL wrote:
How about:
<div tal:define="macroName request/form/id"> <metal:block use-macro="container/zptmac_memtask/macros/?macroName"> List </metal:block> </div>
Combined with renaming your "id" field in your forms (or your macro names, either will do) so they match? That munges the whole list of tal:conditions down to something more manageable...
Heh. After posting this, I looked closer at your list below, and realised you're altering both the macro file name, and the name of the macro inside the file. That'd require that you be able to replace multiple elements of the macro name, rather than a single. That's not doable atm. I still reckon it should be... Then you'd be covered by a tal:define="macroName string:container/zptmac_${request/id}task/macros/zptmac_${request/id}list". Alternately, you can make all macros in macro files be called the same thing - so you end up with a file "zptmac_mempending", which has a macro called "std", and a "zptmac_memtask" which also has a macro called "std", and you just alter one element of the path to the macro, based on the id from the form. KevinL
On Tuesday, August 20, 2002, at 07:18 , zope wrote:
Hi All I am trying to execute a macro only if a condition is satisified. The code I am using is:
<div tal:condition="python:request.form['id'] == 't' | nothing" metal:use-macro="container/zptmac_memtask/macros/zptmac_taskslist"> List </div> <div tal:condition="python:request.form['id'] == 'p' | nothing" metal:use-macro="container/zptmac_mempending/macros/zptmac_pendlist"> List </div> <div tal:condition="python:request.form['id'] == 'w' | nothing" metal:use-macro="container/zptmac_memweek/macros/zptmac_weeklist"> List </div> <div tal:condition="python:request.form['id'] == 'a' | nothing" metal:use-macro="container/zptmac_memall/macros/zptmac_alllist"> List </div>
On Tue, Aug 20, 2002 at 10:11:30PM +1000, KevinL wrote:
Heh. After posting this, I looked closer at your list below, and realised you're altering both the macro file name, and the name of the macro inside the file.
That'd require that you be able to replace multiple elements of the macro name, rather than a single. That's not doable atm. I still reckon it should be... Then you'd be covered by a tal:define="macroName string:container/zptmac_${request/id}task/macros/zptmac_${request/id}list".
Sure you can do it, just use python. How about this; tal:define="macroName python:'container/zptmac_%stask/macros/zptmac_%slist' % (request.form['id'], request.form['id'])" Or if that's too ugly, make it a python script that takes a single "id" parameter and just call that. -- Paul Winkler "Welcome to Muppet Labs, where the future is made - today!"
The way you define macroName wasn't what I was complaining about - it was what you do with macroName afterwards. You can't drop it into the metal use-macro statement, because it contains multiple path elements. That means you likely have to write a python script or python product method to return the macro, instead of finding it in ptl - which means what are essentially display decisions (which template do I use) are being pushed out of ptl. Something else (unconnected) that occurred to me - is "id" still a bad variable name to be using in forms? That one makes me nervous in Zope and MySQL... KJL On Tue, 2002-08-20 at 23:54, Paul Winkler wrote:
On Tue, Aug 20, 2002 at 10:11:30PM +1000, KevinL wrote:
Heh. After posting this, I looked closer at your list below, and realised you're altering both the macro file name, and the name of the macro inside the file.
That'd require that you be able to replace multiple elements of the macro name, rather than a single. That's not doable atm. I still reckon it should be... Then you'd be covered by a tal:define="macroName string:container/zptmac_${request/id}task/macros/zptmac_${request/id}list".
Sure you can do it, just use python. How about this;
tal:define="macroName python:'container/zptmac_%stask/macros/zptmac_%slist' % (request.form['id'], request.form['id'])"
Or if that's too ugly, make it a python script that takes a single "id" parameter and just call that.
--
Paul Winkler "Welcome to Muppet Labs, where the future is made - today!"
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
On Wed, Aug 21, 2002 at 12:05:04AM +1000, KevinL wrote:
The way you define macroName wasn't what I was complaining about - it was what you do with macroName afterwards. You can't drop it into the metal use-macro statement, because it contains multiple path elements.
Oh, I see what you're saying now. Hmmm. hadn't tried that. So you can't do use-macro foo where foo is some complex path? that does kinda suck. --PW - Paul Winkler "Welcome to Muppet Labs, where the future is made - today!"
On Wed, 2002-08-21 at 02:15, Chris Withers wrote:
Paul Winkler wrote:
So you can't do use-macro foo where foo is some complex path?
Yeah, you can...
If you can't, what error do you get?
Chris
Snippet: <span tal:define="macroName string:here/lib/${request/skin}/macros/${request/formname}"> <metal:block use-macro="?macroName"> </metal:block> </span> Doesn't work. Neither does munging things around to make the use-macro something like "here/?macroName". Now ok, in this instance, you can replace the individual elements with ?skin and ?formname in the use-macro itself - but where the path is the result of something more complex (like a python call for multiple elements), it gets more awkward quickly - essentially, ifaics, you have to pull the whole path out to python, rather than just bits of it, and return the actual macro, rather than the path to the macro. The case that started this can be rewritten, with a bit of care and some reshuffling of variable names, to look something like: <metal:block use-macro="container/?id/macros/?id"> </metal:block> ...no tal:conditions or repeating of blocks needed. That requires, however, that "id" in the form be changed to be equal to both the filename and the macroname within the file. Incidentally, if id resolves to an empty string, you'll get errors from the metal code - I think it's trying to slice the empty string in bad ways. Anyway, the original case doesn't suffer from this problem, I was just being overly focussed on what I was battling with elsewhere ;) What I'd like to be able to do, and what I was noting in my email that you can't do, is go: <span tal:define="macroName blah/de/blah/blah"> <metal:block use-macro="here/?macroName"> </metal:block> </span> That, imnsho, would be really useful. At least for us ;) We have a situation where we have here/skins/?skin/?subSkin/pagelayout/macros/std - but the skin, and particularly the subskin, folders don't always exist. For skin, we can easily figure it out, but then we have to call something and tell it which skin we're in, and ask it to work out which subSkin to use - and you can't return a blank string, 'cause metal gets upset. Ideally, we'd have one method that returns the /?skin/?subSkin section (as there's more than just the pagelayout file in there), and refer to use-macro="here/${here/getSkinDir}/pagelayout/macros/std" - where getSkinDir resolves to either /skin or /skin/subSkin, as it needs to (at which point, we also gain arbitrary levels of inheriting skins, which is kinda cute). What we've ended up doing is moving the choice of page and macro out to a python method that returns the actual macro. My problem with this is we then need a tal python call, or we need a separate method for each file we may want skinned - either "here/getPagelayout" (and all other files), or "python:here.getSkinned('pagelayout')". I like the first, I dislike the second - trying to explain the shift from / to . to people who don't know or want to know python but are familiar with html/xml, is just another stumbling block/source of errors. Ideally, we could refer to use-macro="here/${here/getSkinDir}/pagelayout/macros/std" and have getSkinDir give us back multiple path elements. KJL
On Wed, 2002-08-21 at 02:15, Chris Withers wrote:
Paul Winkler wrote:
So you can't do use-macro foo where foo is some complex path?
Yeah, you can...
If you can't, what error do you get?
Chris
Snippet: <span tal:define="macroName string:here/lib/${request/skin}/macros/${request/formname}"> <metal:block use-macro="?macroName"> </metal:block> </span> Doesn't work. Neither does munging things around to make the use-macro something like "here/?macroName". Now ok, in this instance, you can replace the individual elements with ?skin and ?formname in the use-macro itself - but where the path is the result of something more complex (like a python call for multiple elements), it gets more awkward quickly - essentially, ifaics, you have to pull the whole path out to python, rather than just bits of it, and return the actual macro, rather than the path to the macro. The case that started this can be rewritten, with a bit of care and some reshuffling of variable names, to look something like: <metal:block use-macro="container/?id/macros/?id"> </metal:block> ...no tal:conditions or repeating of blocks needed. That requires, however, that "id" in the form be changed to be equal to both the filename and the macroname within the file. Incidentally, if id resolves to an empty string, you'll get errors from the metal code - I think it's trying to slice the empty string in bad ways. Anyway, the original case doesn't suffer from this problem, I was just being overly focussed on what I was battling with elsewhere ;) What I'd like to be able to do, and what I was noting in my email that you can't do, is go: <span tal:define="macroName blah/de/blah/blah"> <metal:block use-macro="here/?macroName"> </metal:block> </span> That, imnsho, would be really useful. At least for us ;) We have a situation where we have here/skins/?skin/?subSkin/pagelayout/macros/std - but the skin, and particularly the subskin, folders don't always exist. For skin, we can easily figure it out, but then we have to call something and tell it which skin we're in, and ask it to work out which subSkin to use - and you can't return a blank string, 'cause metal gets upset. Ideally, we'd have one method that returns the /?skin/?subSkin section (as there's more than just the pagelayout file in there), and refer to use-macro="here/${here/getSkinDir}/pagelayout/macros/std" - where getSkinDir resolves to either /skin or /skin/subSkin, as it needs to (at which point, we also gain arbitrary levels of inheriting skins, which is kinda cute). What we've ended up doing is moving the choice of page and macro out to a python method that returns the actual macro. My problem with this is we then need a tal python call, or we need a separate method for each file we may want skinned - either "here/getPagelayout" (and all other files), or "python:here.getSkinned('pagelayout')". I like the first, I dislike the second - trying to explain the shift from / to . to people who don't know or want to know python but are familiar with html/xml, is just another stumbling block/source of errors. Ideally, we could refer to use-macro="here/${here/getSkinDir}/pagelayout/macros/std" and have getSkinDir give us back multiple path elements. KJL
Hi Jens I have tried the method you have suggested but I think the first time the page is loaded one value for the variable "id" is being expected . So I am getting an error like this: The XML page cannot be displayed Cannot view XML input using XSL style sheet. Please correct the error and then click the button, or try again later. ---------------------------------------------------------------------------- -- A name contained an invalid character. Error processing resource 'http://192.168.10.11:8080/oms/Users/pl'. Line 3, Position 56 exceptions.KeyError on id in "<PythonExpr request.form['id'] == 't' or nothing>" -------------------------------------------------------^ Could you tell me how I can rewrite this so that the first time the page is loaded even if there is no value for "id" the page will be shown . And only if I pass a form variable it should execute. Thanks and Best Regards John Kunchandy ----- Original Message ----- From: "Jens Vagelpohl" To: "zope" Cc: Sent: Tuesday, August 20, 2002 5:26 PM Subject: Re: [Zope] Tal:condition problem
i would *not* put both the tal:condition and metal:use-macro statements on a single tag. separate them so each is on its own tag::
<div tal:condition="python:request.form['id'] == 't' or nothing"> <metal:block use-macro="container/zptmac_memtask/macros/zptmac_taskslist"
List </metal:block> </div>
jens
On Tuesday, August 20, 2002, at 07:18 , zope wrote:
Hi All I am trying to execute a macro only if a condition is satisified. The code I am using is:
<div tal:condition="python:request.form['id'] == 't' | nothing" metal:use-macro="container/zptmac_memtask/macros/zptmac_taskslist"> List </div> <div tal:condition="python:request.form['id'] == 'p' | nothing" metal:use-macro="container/zptmac_mempending/macros/zptmac_pendlist"> List </div> <div tal:condition="python:request.form['id'] == 'w' | nothing" metal:use-macro="container/zptmac_memweek/macros/zptmac_weeklist"> List </div> <div tal:condition="python:request.form['id'] == 'a' | nothing" metal:use-macro="container/zptmac_memall/macros/zptmac_alllist"> List </div> Depending on which value is passed with the form object i want that a particular macro be called. But as soon as this page is rendered it shows me all the macros irrespective of whether I am sending any value for "id". Is there some way I can check the condition and only show the required macro. I m sure someone working on this particular area dealing with different conditions can help me out.
Best Regards John Kunchandy
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.381 / Virus Database: 214 - Release Date: 8/2/2002
zope wrote:
exceptions.KeyError on id in "<PythonExpr request.form['id'] == 't' or nothing>" -------------------------------------------------------^ Could you tell me how I can rewrite this so that the first time the page is loaded even if there is no value for "id" the page will be shown . And only if I pass a form variable it should execute.
Try replacing "request.form['id'] == 't' or nothing" with: request.form.get(id')=='t' cheers, Chris
participants (5)
-
Chris Withers -
Jens Vagelpohl -
KevinL -
Paul Winkler -
zope