Hi; I´m trying to increment a variable in a page template. Here´s the general idea in my code: <div metal:define-macro="main" tal:define="x python:0"> <tal:block tal:define="x python:x + 1"> <td> <input type="hidden" tal:attributes="value item/name; name python:'item_name_' + `x`"> Now, all of that works...once. That is, it increments from 0 to 1, but not from 1 to 2! Each time I pass through the td element, I need it to increment. I tried putting the tal definition in the td, but then it didn´t even increment once! What do? TIA, Tony ________________________________________________________________________ AOL now offers free email to everyone. Find out more about what's free from AOL at AOL.com.
--On 30. Juli 2007 10:16:35 -0400 tonylabarbara@aol.com wrote:
Hi; I´m trying to increment a variable in a page template. Here´s the general idea in my code:
<div metal:define-macro="main" tal:define="x python:0">
Why do you need a counter in ZPT? This is absolutely one of the worst things you can go in ZPT. Describe your concrete use-case and we might think about a suitable and clean solution. But thinking about counters in ZPT is a waste of life-time. -aj
In order to interact with the paypal shopping cart system, they want me to increment hidden fields, such as: <input type="hidden" tal:attributes="value item/name; name python:'item_name_' + `x`"> <input type="hidden" tal:attributes="value item/id; name python:'item_number_' + `x`"> where "x" is a number from 1 on up, where "1" represents the first product in the shopping cart, "2" represents the second product, etc. So...we have to do it their way. Perhaps this is really bad ZPT, but we have to do it their way. Can ZPT handle this, or not? TIA, Tony -----Original Message----- From: Andreas Jung <lists@zopyx.com> To: tonylabarbara@aol.com; zope@zope.org Sent: Mon, 30 Jul 2007 10:23 am Subject: Re: [Zope] Increment In PT? --On 30. Juli 2007 10:16:35 -0400 tonylabarbara@aol.com wrote:
Hi; I´m trying to increment a variable in a page template. Here´s the general idea in my code: <div metal:define-macro="main" tal:define="x python:0"> Why do you need a counter in ZPT? This is absolutely one of the worst things you can go in ZPT. Describe your concrete use-case and we might think about a suitable and clean solution. But thinking about counters in ZPT is a waste of life-time. -aj
________________________________________________________________________ AOL now offers free email to everyone. Find out more about what's free from AOL at AOL.com.
+-------[ tonylabarbara@aol.com ]---------------------- | In order to interact with the paypal shopping cart system, they want me to | increment hidden fields, such as: | | <input type="hidden" tal:attributes="value item/name; name python:'item_name_' | + `x`"> | <input type="hidden" tal:attributes="value item/id; name python:'item_number_' | + `x`"> | | where "x" is a number from 1 on up, where "1" represents the first product in | the shopping cart, "2" represents the second product, etc. So...we have to do | it their way. Perhaps this is really bad ZPT, but we have to do it their way. | Can ZPT handle this, or not? 1) Why not use the "enumerate" method in your repeat? 2) Why not pass the items to a python script that builds the structure you need and returns it? -- Andrew Milton akm@theinternet.com.au
Can you give me an example of how to use the enumerate method in a repeat? I've googled this with no luck. Here's my tal:repeat clause: ????? <span tal:repeat="bitem_id bitem_ids;" tal:omit-tag=""> As fas as passing this to a python script, I'd rather not. That seems like too much trouble for something that IMHO should be easy, and if it's not, perhaps the gods of PT would like to do something about it. TIA, Tony -----Original Message----- From: Andrew Milton <akm@theinternet.com.au> To: tonylabarbara@aol.com Cc: lists@zopyx.com; zope@zope.org Sent: Mon, 30 Jul 2007 12:30 pm Subject: Re: [Zope] Increment In PT? +-------[ tonylabarbara@aol.com ]---------------------- | In order to interact with the paypal shopping cart system, they want me to | increment hidden fields, such as: | | <input type="hidden" tal:attributes="value item/name; name python:'item_name_' | + `x`"> | <input type="hidden" tal:attributes="value item/id; name python:'item_number_' | + `x`"> | | where "x" is a number from 1 on up, where "1" represents the first product in | the shopping cart, "2" represents the second product, etc. So...we have to do | it their way. Perhaps this is really bad ZPT, but we have to do it their way. | Can ZPT handle this, or not? 1) Why not use the "enumerate" method in your repeat? 2) Why not pass the items to a python script that builds the structure you need and returns it? -- Andrew Milton akm@theinternet.com.au ________________________________________________________________________ AOL now offers free email to everyone. Find out more about what's free from AOL at AOL.com.
You can use the ZTUtils Iterator() <div tal:define="iter python:modules['ZTUtils'].Iterator(range(1000))"> <br tal:define="dummy iter/next" tal:replace="iter/number" /> <br tal:define="dummy iter/next" tal:replace="iter/number" /> <br tal:define="dummy iter/next" tal:replace="iter/number" /> </div> Which might give you some freedom such as iter/Roman or iter/odd The above is practically the same as: <br tal:repeat="i python:range(3)" tal:replace="i" /> Generally, if you can, use a Python Script or something. The Iterator is/was used in Plone templates to increment the tab index. tonylabarbara@aol.com wrote:
Hi; I´m trying to increment a variable in a page template. Here´s the general idea in my code:
<div metal:define-macro="main" tal:define="x python:0">
<tal:block tal:define="x python:x + 1"> <td> <input type="hidden" tal:attributes="value item/name; name python:'item_name_' + `x`">
Now, all of that works...once. That is, it increments from 0 to 1, but not from 1 to 2! Each time I pass through the td element, I need it to increment. I tried putting the tal definition in the td, but then it didn´t even increment once! What do? TIA, Tony ------------------------------------------------------------------------ AOL now offers free email to everyone. Find out more about what's free from AOL at *AOL.com* <http://www.aol.com?ncid=AOLAOF00020000000437>.
------------------------------------------------------------------------
_______________________________________________ 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 )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
I would think this should be pretty easy in the PT itself, given what you've shared so far. But I'm still not quite there. Here's what I've got: <span tal:repeat="bitem_id bitem_ids" tal:omit-tag=""> <div tal:define="iter python:modules['ZTUtils'].Iterator(range(1000))"> <br tal:define="x iter/next" tal:replace="iter/number" /> Now, I don't really want that <br /> tag there, because it's printing a number to screen that I don't want there. However, it only prints the number "1" twice, once for each product, when it should print 1 then 2, I would think. (I presume I should just take the tal:replace out and leave the definition, but it's still not incrementing!) Later in the script I have this: <input type="hidden" tal:attributes="value item/name; name python:'item_name_' + `x`"> <input type="hidden" tal:attributes="value item/id; name python:'item_number_' + `x`"> and other similar lines. What I'm trying to effectuate is that the "x" gets replaced with an incremented number. Can you help just a little more? TIA, Tony -----Original Message----- From: Peter Bengtsson <peter@fry-it.com> To: tonylabarbara@aol.com Cc: zope@zope.org Sent: Mon, 30 Jul 2007 1:32 pm Subject: Re: [Zope] Increment In PT? You can use the ZTUtils Iterator() <div tal:define="iter python:modules['ZTUtils'].Iterator(range(1000))"> <br tal:define="dummy iter/next" tal:replace="iter/number" /> <br tal:define="dummy iter/next" tal:replace="iter/number" /> <br tal:define="dummy iter/next" tal:replace="iter/number" /> </div> Which might give you some freedom such as iter/Roman or iter/odd The above is practically the same as: <br tal:repeat="i python:range(3)" tal:replace="i" /> Generally, if you can, use a Python Script or something. The Iterator is/was used in Plone templates to increment the tab index. tonylabarbara@aol.com wrote:
Hi; I´m trying to increment a variable in a page template. Here´s the > general idea in my code:
<div metal:define-macro="main" tal:define="x python:0"> <tal:block tal:define="x python:x + 1"> <td> <input type="hidden" tal:attributes="value item/name; name > python:'item_name_' + `x`">
Now, all of that works...once. That is, it increments from 0 to 1, but > not from 1 to 2! Each time I pass through the td element, I need it to > increment. I tried putting the tal definition in the td, but then it > didn´t even increment once! What do? TIA, Tony ------------------------------------------------------------------------ AOL now offers free email to everyone. Find out more about what's free > from AOL at *AOL.com* <http://www.aol.com?ncid=AOLAOF00020000000437>. ------------------------------------------------------------------------ _______________________________________________ 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 ) -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
________________________________________________________________________ AOL now offers free email to everyone. Find out more about what's free from AOL at AOL.com.
You should now have all the parts. Instead of iterating over python:range(1000) do it on bitem_ids instead. You don't have to use a <br /> tag. You can use <input tal:attributes="value iter/number" /> if you want. You increment it by calling tal:iter/next whichever way you do it. tonylabarbara@aol.com wrote:
I would think this should be pretty easy in the PT itself, given what you've shared so far. But I'm still not quite there. Here's what I've got:
<span tal:repeat="bitem_id bitem_ids" tal:omit-tag=""> <div tal:define="iter python:modules['ZTUtils'].Iterator(range(1000))"> <br tal:define="x iter/next" tal:replace="iter/number" />
Now, I don't really want that <br /> tag there, because it's printing a number to screen that I don't want there. However, it only prints the number "1" twice, once for each product, when it should print 1 then 2, I would think. (I presume I should just take the tal:replace out and leave the definition, but it's still not incrementing!) Later in the script I have this:
<input type="hidden" tal:attributes="value item/name; name python:'item_name_' + `x`"> <input type="hidden" tal:attributes="value item/id; name python:'item_number_' + `x`">
and other similar lines. What I'm trying to effectuate is that the "x" gets replaced with an incremented number. Can you help just a little more? TIA, Tony
-----Original Message----- From: Peter Bengtsson <peter@fry-it.com> To: tonylabarbara@aol.com Cc: zope@zope.org Sent: Mon, 30 Jul 2007 1:32 pm Subject: Re: [Zope] Increment In PT?
You can use the ZTUtils Iterator()
<div tal:define="iter python:modules['ZTUtils'].Iterator(range(1000))"> <br tal:define="dummy iter/next" tal:replace="iter/number" /> <br tal:define="dummy iter/next" tal:replace="iter/number" /> <br tal:define="dummy iter/next" tal:replace="iter/number" /> </div>
Which might give you some freedom such as iter/Roman or iter/odd The above is practically the same as:
<br tal:repeat="i python:range(3)" tal:replace="i" />
Generally, if you can, use a Python Script or something. The Iterator is/was used in Plone templates to increment the tab index.
tonylabarbara@aol.com <mailto:tonylabarbara@aol.com> wrote:
Hi; I´m trying to increment a variable in a page template. Here´s the > general idea in my code:
<div metal:define-macro="main" tal:define="x python:0"> <tal:block tal:define="x python:x + 1"> <td> <input type="hidden" tal:attributes="value item/name; name > python:'item_name_' + `x`">
Now, all of that works...once. That is, it increments from 0 to 1, but > not from 1 to 2! Each time I pass through the td element, I need it to > increment. I tried putting the tal definition in the td, but then it > didn´t even increment once! What do? TIA, Tony
AOL now offers free email to everyone. Find out more about what's free > from AOL at *AOL.com* <http://www.aol.com?ncid=AOLAOF00020000000437 <http://www.aol.com/?ncid=AOLAOF00020000000437>>.
_______________________________________________ Zope maillist - Zope@zope.org <mailto: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 )
-- Peter Bengtsson, work www.fry-it.com <http://www.fry-it.com/> home www.peterbe.com <http://www.peterbe.com/> hobby www.issuetrackerproduct.com <http://www.issuetrackerproduct.com/> ------------------------------------------------------------------------ AOL now offers free email to everyone. Find out more about what's free from AOL at *AOL.com* <http://www.aol.com?ncid=AOLAOF00020000000437>.
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
Try this way: <tal:loop repeat="item bitems"> <input type="hidden" tal:attributes="value item/name; name string:item_name_${repeat/item/number}"> <input type="hidden" tal:attributes="value item/id; name string:item_number_${repeat/item/number}"> </tal:loop> Zenrique. 2007/7/30, Peter Bengtsson <peter@fry-it.com>:
You should now have all the parts. Instead of iterating over python:range(1000) do it on bitem_ids instead.
You don't have to use a <br /> tag. You can use <input tal:attributes="value iter/number" /> if you want. You increment it by calling tal:iter/next whichever way you do it.
tonylabarbara@aol.com wrote:
I would think this should be pretty easy in the PT itself, given what you've shared so far. But I'm still not quite there. Here's what I've got:
<span tal:repeat="bitem_id bitem_ids" tal:omit-tag=""> <div tal:define="iter python:modules['ZTUtils'].Iterator(range(1000))"> <br tal:define="x iter/next" tal:replace="iter/number" />
Now, I don't really want that <br /> tag there, because it's printing a number to screen that I don't want there. However, it only prints the number "1" twice, once for each product, when it should print 1 then 2, I would think. (I presume I should just take the tal:replace out and leave the definition, but it's still not incrementing!) Later in the script I have this:
<input type="hidden" tal:attributes="value item/name; name python:'item_name_' + `x`"> <input type="hidden" tal:attributes="value item/id; name python:'item_number_' + `x`">
and other similar lines. What I'm trying to effectuate is that the "x" gets replaced with an incremented number. Can you help just a little more? TIA, Tony
-----Original Message----- From: Peter Bengtsson <peter@fry-it.com> To: tonylabarbara@aol.com Cc: zope@zope.org Sent: Mon, 30 Jul 2007 1:32 pm Subject: Re: [Zope] Increment In PT?
You can use the ZTUtils Iterator()
<div tal:define="iter python:modules['ZTUtils'].Iterator(range(1000))"> <br tal:define="dummy iter/next" tal:replace="iter/number" /> <br tal:define="dummy iter/next" tal:replace="iter/number" /> <br tal:define="dummy iter/next" tal:replace="iter/number" /> </div>
Which might give you some freedom such as iter/Roman or iter/odd The above is practically the same as:
<br tal:repeat="i python:range(3)" tal:replace="i" />
Generally, if you can, use a Python Script or something. The Iterator is/was used in Plone templates to increment the tab index.
tonylabarbara@aol.com <mailto:tonylabarbara@aol.com> wrote:
Hi; I´m trying to increment a variable in a page template. Here´s the > general idea in my code:
<div metal:define-macro="main" tal:define="x python:0"> <tal:block tal:define="x python:x + 1"> <td> <input type="hidden" tal:attributes="value item/name; name > python:'item_name_' + `x`">
Now, all of that works...once. That is, it increments from 0 to 1, but > not from 1 to 2! Each time I pass through the td element, I need it to > increment. I tried putting the tal definition in the td, but then it > didn´t even increment once! What do? TIA, Tony
AOL now offers free email to everyone. Find out more about what's free > from AOL at *AOL.com* <http://www.aol.com?ncid=AOLAOF00020000000437 <http://www.aol.com/?ncid=AOLAOF00020000000437>>.
_______________________________________________ Zope maillist - Zope@zope.org <mailto: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 )
-- Peter Bengtsson, work www.fry-it.com <http://www.fry-it.com/> home www.peterbe.com <http://www.peterbe.com/> hobby www.issuetrackerproduct.com <http://www.issuetrackerproduct.com/> ------------------------------------------------------------------------ AOL now offers free email to everyone. Find out more about what's free from AOL at *AOL.com* <http://www.aol.com?ncid=AOLAOF00020000000437>.
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com _______________________________________________ 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 )
It's complaining that: Error Type: TypeError Error Value: string indices must be integers I tried back ticks and that still gave the same error. TIA, Tony <tal:loop repeat="item bitems"> <input type="hidden" tal:attributes="value item/name; name string:item_name_${repeat/item/number}"> <input type="hidden" tal:attributes="value item/id; name string:item_number_${repeat/item/number}"> </tal:loop> -----Original Message----- From: José Henrique <jhreis@gmail.com> To: zope@zope.org Sent: Mon, 30 Jul 2007 2:07 pm Subject: Re: [Zope] Increment In PT? Try this way: <tal:loop repeat="item bitems"> <input type="hidden" tal:attributes="value item/name; name string:item_name_${repeat/item/number}"> <input type="hidden" tal:attributes="value item/id; name string:item_number_${repeat/item/number}"> </tal:loop> Zenrique. 2007/7/30, Peter Bengtsson <peter@fry-it.com>: You should now have all the parts. Instead of iterating over python:range(1000) do it on bitem_ids instead. You don't have to use a <br /> tag. You can use <input tal:attributes="value iter/number" /> if you want. You increment it by calling tal:iter/next whichever way you do it. tonylabarbara@aol.com wrote:
I would think this should be pretty easy in the PT itself, given what you've shared so far. But I'm still not quite there. Here's what I've got:
<span tal:repeat="bitem_id bitem_ids" tal:omit-tag=""> <div tal:define="iter python:modules['ZTUtils'].Iterator(range(1000))"> <br tal:define="x iter/next" tal:replace="iter/number" />
Now, I don't really want that <br /> tag there, because it's printing a number to screen that I don't want there. However, it only prints the number "1" twice, once for each product, when it should print 1 then 2, I would think. (I presume I should just take the tal:replace out and leave the definition, but it's still not incrementing!) Later in the script I have this:
<input type="hidden" tal:attributes="value item/name; name python:'item_name_' + `x`"> <input type="hidden" tal:attributes="value item/id; name python:'item_number_' + `x`">
and other similar lines. What I'm trying to effectuate is that the "x" gets replaced with an incremented number. Can you help just a little more? TIA, Tony
-----Original Message----- From: Peter Bengtsson < peter@fry-it.com> To: tonylabarbara@aol.com Cc: zope@zope.org Sent: Mon, 30 Jul 2007 1:32 pm Subject: Re: [Zope] Increment In PT?
You can use the ZTUtils Iterator()
<div tal:define="iter python:modules['ZTUtils'].Iterator(range(1000))"> <br tal:define="dummy iter/next" tal:replace="iter/number" /> <br tal:define="dummy iter/next" tal:replace="iter/number" /> <br tal:define="dummy iter/next" tal:replace="iter/number" /> </div>
Which might give you some freedom such as iter/Roman or iter/odd The above is practically the same as:
<br tal:repeat="i python:range(3)" tal:replace="i" />
Generally, if you can, use a Python Script or something. The Iterator is/was used in Plone templates to increment the tab index.
tonylabarbara@aol.com <mailto:tonylabarbara@aol.com> wrote: > Hi; > I´m trying to increment a variable in a page template. Here´s the > general idea in my code: > > <div metal:define-macro="main" tal:define="x python:0"> > > <tal:block tal:define="x python:x + 1"> > <td> > <input type="hidden" tal:attributes="value item/name; name > python:'item_name_' + `x`"> > > > Now, all of that works...once. That is, it increments from 0 to 1, but > not from 1 to 2! Each time I pass through the td element, I need it to > increment. I tried putting the tal definition in the td, but then it > didn´t even increment once! What do? > TIA, > Tony > ------------------------------------------------------------------------ > AOL now offers free email to everyone. Find out more about what's free > from AOL at *AOL.com* <http://www.aol.com?ncid=AOLAOF00020000000437 <http://www.aol.com/?ncid=AOLAOF00020000000437>>. > > > ------------------------------------------------------------------------ > > _______________________________________________ > Zope maillist - Zope@zope.org <mailto: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 )
-- Peter Bengtsson, work www.fry-it.com <http://www.fry-it.com/> home www.peterbe.com < http://www.peterbe.com/> hobby www.issuetrackerproduct.com <http://www.issuetrackerproduct.com/> ------------------------------------------------------------------------ AOL now offers free email to everyone. Find out more about what's free from AOL at *AOL.com* <http://www.aol.com?ncid=AOLAOF00020000000437 >.
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com _______________________________________________ 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 ) _______________________________________________ ope maillist - Zope@zope.org ttp://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 ) ________________________________________________________________________ AOL now offers free email to everyone. Find out more about what's free from AOL at AOL.com.
I understood that 'bitems' was a sequence of dictionaries. Ex: ({'name': 'xyz', 'id': 1'},{'name': 'pex', 'id': 2},{'name': 'wei', 'id': 3}...). If it's something different, you have to change the code to handle your object properly. Zenrique. 2007/7/30, tonylabarbara@aol.com <tonylabarbara@aol.com>:
It's complaining that: *Error Type: TypeError* *Error Value: string indices must be integers* I tried back ticks and that still gave the same error. TIA, Tony
<tal:loop repeat="item bitems"> <input type="hidden" tal:attributes="value item/name; name string:item_name_${repeat/item/number}"> <input type="hidden" tal:attributes="value item/id; name string:item_number_${repeat/item/number}"> </tal:loop>
This is the code that I have: <span tal:repeat="bitem_id bitem_ids" tal:omit-tag=""> <span tal:define="bitem python:here.basketItemManager.getItem(bitem_id); item python:here.marketItems.getItem(bitem.marketItemId)" tal:omit-tag=""> This is the code that I would like to write: <span tal:repeat="bitem_id bitem_ids" tal:omit-tag="" """for each new bitem_id increment x"""> <span tal:define="bitem python:here.basketItemManager.getItem(bitem_id); item python:here.marketItems.getItem(bitem.marketItemId)" tal:omit-tag=""> How can I do that? TIA, Tony -----Original Message----- From: tonylabarbara@aol.com To: jhreis@gmail.com; zope@zope.org Sent: Mon, 30 Jul 2007 2:30 pm Subject: Re: [Zope] Increment In PT? It's complaining that: Error Type: TypeError Error Value: string indices must be integers I tried back ticks and that still gave the same error. TIA, Tony <tal:loop repeat="item bitems"> <input type="hidden" tal:attributes="value item/name; name string:item_name_${repeat/item/number}"> <input type="hidden" tal:attributes="value item/id; name string:item_number_${repeat/item/number}"> </tal:loop> -----Original Message----- From: José Henrique <jhreis@gmail.com> To: zope@zope.org Sent: Mon, 30 Jul 2007 2:07 pm Subject: Re: [Zope] Increment In PT? Try this way: <tal:loop repeat="item bitems"> <input type="hidden" tal:attributes="value item/name; name string:item_name_${repeat/item/number}"> <input type="hidden" tal:attributes="value item/id; name string:item_number_${repeat/item/number}"> </tal:loop> Zenrique. 2007/7/30, Peter Bengtsson <peter@fry-it.com>: You should now have all the parts. Instead of iterating over python:range(1000) do it on bitem_ids instead. You don't have to use a <br /> tag. You can use <input tal:attributes="value iter/number" /> if you want. You increment it by calling tal:iter/next whichever way you do it. tonylabarbara@aol.com wrote:
I would think this should be pretty easy in the PT itself, given what you've shared so far. But I'm still not quite there. Here's what I've got:
<span tal:repeat="bitem_id bitem_ids" tal:omit-tag=""> <div tal:define="iter python:modules['ZTUtils'].Iterator(range(1000))"> <br tal:define="x iter/next" tal:replace="iter/number" />
Now, I don't really want that <br /> tag there, because it's printing a number to screen that I don't want there. However, it only prints the number "1" twice, once for each product, when it should print 1 then 2, I would think. (I presume I should just take the tal:replace out and leave the definition, but it's still not incrementing!) Later in the script I have this:
<input type="hidden" tal:attributes="value item/name; name python:'item_name_' + `x`"> <input type="hidden" tal:attributes="value item/id; name python:'item_number_' + `x`">
and other similar lines. What I'm trying to effectuate is that the "x" gets replaced with an incremented number. Can you help just a little more? TIA, Tony
-----Original Message----- From: Peter Bengtsson < peter@fry-it.com> To: tonylabarbara@aol.com Cc: zope@zope.org Sent: Mon, 30 Jul 2007 1:32 pm Subject: Re: [Zope] Increment In PT?
You can use the ZTUtils Iterator()
<div tal:define="iter python:modules['ZTUtils'].Iterator(range(1000))"> <br tal:define="dummy iter/next" tal:replace="iter/number" /> <br tal:define="dummy iter/next" tal:replace="iter/number" /> <br tal:define="dummy iter/next" tal:replace="iter/number" /> </div>
Which might give you some freedom such as iter/Roman or iter/odd The above is practically the same as:
<br tal:repeat="i python:range(3)" tal:replace="i" />
Generally, if you can, use a Python Script or something. The Iterator is/was used in Plone templates to increment the tab index.
tonylabarbara@aol.com <mailto:tonylabarbara@aol.com> wrote: > Hi; > I´m trying to increment a variable in a page template. Here´s the > general idea in my code: > > <div metal:define-macro="main" tal:define="x python:0"> > > <tal:block tal:define="x python:x + 1"> > <td> > <input type="hidden" tal:attributes="value item/name; name > python:'item_name_' + `x`"> > > > Now, all of that works...once. That is, it increments from 0 to 1, but > not from 1 to 2! Each time I pass through the td element, I need it to > increment. I tried putting the tal definition in the td, but then it > didn´t even increment once! What do? > TIA, > Tony > ------------------------------------------------------------------------ > AOL now offers free email to everyone. Find out more about what's free > from AOL at *AOL.com* <http://www.aol.com?ncid=AOLAOF00020000000437 <http://www.aol.com/?ncid=AOLAOF00020000000437>>. > > > ------------------------------------------------------------------------ > > _______________________________________________ > Zope maillist - Zope@zope.org <mailto: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 )
-- Peter Bengtsson, work www.fry-it.com <http://www.fry-it.com/> home www.peterbe.com < http://www.peterbe.com/> hobby www.issuetrackerproduct.com <http://www.issuetrackerproduct.com/> ------------------------------------------------------------------------ AOL now offers free email to everyone. Find out more about what's free from AOL at *AOL.com* <http://www.aol.com?ncid=AOLAOF00020000000437 >.
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com _______________________________________________ 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 ) _______________________________________________ ope maillist - Zope@zope.org ttp://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 ) AOL now offers free email to everyone. Find out more about what's free from AOL at AOL.com. _______________________________________________ ope maillist - Zope@zope.org ttp://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 ) ________________________________________________________________________ AOL now offers free email to everyone. Find out more about what's free from AOL at AOL.com.
Well, there I go making mountains out of molehills again. This worked just fine: <span tal:define="bitem python:here.basketItemManager.getItem(bitem_id); item python:here.marketItems.getItem(bitem.marketItemId); x repeat/bitem_id/number" tal:omit-tag=""> Thanks for all, Tony -----Original Message----- From: tonylabarbara@aol.com To: jhreis@gmail.com; zope@zope.org Sent: Mon, 30 Jul 2007 2:30 pm Subject: Re: [Zope] Increment In PT? It's complaining that: Error Type: TypeError Error Value: string indices must be integers I tried back ticks and that still gave the same error. TIA, Tony <tal:loop repeat="item bitems"> <input type="hidden" tal:attributes="value item/name; name string:item_name_${repeat/item/number}"> <input type="hidden" tal:attributes="value item/id; name string:item_number_${repeat/item/number}"> </tal:loop> -----Original Message----- From: José Henrique <jhreis@gmail.com> To: zope@zope.org Sent: Mon, 30 Jul 2007 2:07 pm Subject: Re: [Zope] Increment In PT? Try this way: <tal:loop repeat="item bitems"> <input type="hidden" tal:attributes="value item/name; name string:item_name_${repeat/item/number}"> <input type="hidden" tal:attributes="value item/id; name string:item_number_${repeat/item/number}"> </tal:loop> Zenrique. 2007/7/30, Peter Bengtsson <peter@fry-it.com>: You should now have all the parts. Instead of iterating over python:range(1000) do it on bitem_ids instead. You don't have to use a <br /> tag. You can use <input tal:attributes="value iter/number" /> if you want. You increment it by calling tal:iter/next whichever way you do it. tonylabarbara@aol.com wrote:
I would think this should be pretty easy in the PT itself, given what you've shared so far. But I'm still not quite there. Here's what I've got:
<span tal:repeat="bitem_id bitem_ids" tal:omit-tag=""> <div tal:define="iter python:modules['ZTUtils'].Iterator(range(1000))"> <br tal:define="x iter/next" tal:replace="iter/number" />
Now, I don't really want that <br /> tag there, because it's printing a number to screen that I don't want there. However, it only prints the number "1" twice, once for each product, when it should print 1 then 2, I would think. (I presume I should just take the tal:replace out and leave the definition, but it's still not incrementing!) Later in the script I have this:
<input type="hidden" tal:attributes="value item/name; name python:'item_name_' + `x`"> <input type="hidden" tal:attributes="value item/id; name python:'item_number_' + `x`">
and other similar lines. What I'm trying to effectuate is that the "x" gets replaced with an incremented number. Can you help just a little more? TIA, Tony
-----Original Message----- From: Peter Bengtsson < peter@fry-it.com> To: tonylabarbara@aol.com Cc: zope@zope.org Sent: Mon, 30 Jul 2007 1:32 pm Subject: Re: [Zope] Increment In PT?
You can use the ZTUtils Iterator()
<div tal:define="iter python:modules['ZTUtils'].Iterator(range(1000))"> <br tal:define="dummy iter/next" tal:replace="iter/number" /> <br tal:define="dummy iter/next" tal:replace="iter/number" /> <br tal:define="dummy iter/next" tal:replace="iter/number" /> </div>
Which might give you some freedom such as iter/Roman or iter/odd The above is practically the same as:
<br tal:repeat="i python:range(3)" tal:replace="i" />
Generally, if you can, use a Python Script or something. The Iterator is/was used in Plone templates to increment the tab index.
tonylabarbara@aol.com <mailto:tonylabarbara@aol.com> wrote: > Hi; > I´m trying to increment a variable in a page template. Here´s the > general idea in my code: > > <div metal:define-macro="main" tal:define="x python:0"> > > <tal:block tal:define="x python:x + 1"> > <td> > <input type="hidden" tal:attributes="value item/name; name > python:'item_name_' + `x`"> > > > Now, all of that works...once. That is, it increments from 0 to 1, but > not from 1 to 2! Each time I pass through the td element, I need it to > increment. I tried putting the tal definition in the td, but then it > didn´t even increment once! What do? > TIA, > Tony > ------------------------------------------------------------------------ > AOL now offers free email to everyone. Find out more about what's free > from AOL at *AOL.com* <http://www.aol.com?ncid=AOLAOF00020000000437 <http://www.aol.com/?ncid=AOLAOF00020000000437>>. > > > ------------------------------------------------------------------------ > > _______________________________________________ > Zope maillist - Zope@zope.org <mailto: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 )
-- Peter Bengtsson, work www.fry-it.com <http://www.fry-it.com/> home www.peterbe.com < http://www.peterbe.com/> hobby www.issuetrackerproduct.com <http://www.issuetrackerproduct.com/> ------------------------------------------------------------------------ AOL now offers free email to everyone. Find out more about what's free from AOL at *AOL.com* <http://www.aol.com?ncid=AOLAOF00020000000437 >.
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com _______________________________________________ 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 ) _______________________________________________ ope maillist - Zope@zope.org ttp://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 ) AOL now offers free email to everyone. Find out more about what's free from AOL at AOL.com. _______________________________________________ ope maillist - Zope@zope.org ttp://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 ) ________________________________________________________________________ AOL now offers free email to everyone. Find out more about what's free from AOL at AOL.com.
Okay, I've got this line: <div tal:define="iter python:modules['ZTUtils'].Iterator(range(1000)); x iter/next"> and then use this kind of line several times further down and within the div: <input type="hidden" tal:attributes="value bitem/quantity; name python:'quantity_' + `x`"> What this yields is lines like this: <input type="hidden" name="item_name_1" value="17x25"> but it never increments! And I have 3 items! How do I get it to increment? TIA, Tony -----Original Message----- From: Peter Bengtsson <peter@fry-it.com> To: tonylabarbara@aol.com Cc: zope@zope.org Sent: Mon, 30 Jul 2007 1:52 pm Subject: Re: [Zope] Increment In PT? You should now have all the parts. Instead of iterating over python:range(1000) do it on bitem_ids instead. You don't have to use a <br /> tag. You can use <input tal:attributes="value iter/number" /> if you want. You increment it by calling tal:iter/next whichever way you do it. tonylabarbara@aol.com wrote:
I would think this should be pretty easy in the PT itself, given what > you've shared so far. But I'm still not quite there. Here's what I've got:
<span tal:repeat="bitem_id bitem_ids" tal:omit-tag=""> <div tal:define="iter > python:modules['ZTUtils'].Iterator(range(1000))"> <br tal:define="x iter/next" tal:replace="iter/number" /> Now, I don't really want that <br /> tag there, because it's printing a > number to screen that I don't want there. However, it only prints the > number "1" twice, once for each product, when it should print 1 then 2, > I would think. (I presume I should just take the tal:replace out and > leave the definition, but it's still not incrementing!) Later in the > script I have this: <input type="hidden" tal:attributes="value item/name; > name python:'item_name_' + `x`"> <input type="hidden" tal:attributes="value item/id; name > python:'item_number_' + `x`"> and other similar lines. What I'm trying to effectuate is that the "x" > gets replaced with an incremented number. Can you help just a little more? TIA, Tony -----Original Message----- From: Peter Bengtsson <peter@fry-it.com> To: tonylabarbara@aol.com Cc: zope@zope.org Sent: Mon, 30 Jul 2007 1:32 pm Subject: Re: [Zope] Increment In PT? You can use the ZTUtils Iterator() > > <div tal:define="iter python:modules['ZTUtils'].Iterator(range(1000))"> > <br tal:define="dummy iter/next" tal:replace="iter/number" /> > <br tal:define="dummy iter/next" tal:replace="iter/number" /> > <br tal:define="dummy iter/next" tal:replace="iter/number" /> > </div> > > Which might give you some freedom such as iter/Roman or iter/odd > The above is practically the same as: > > <br tal:repeat="i python:range(3)" tal:replace="i" /> > > Generally, if you can, use a Python Script or something. The Iterator > is/was used in Plone templates to increment the tab index. > > tonylabarbara@aol.com <mailto:tonylabarbara@aol.com> wrote: > > Hi; > > I´m trying to increment a variable in a page template. Here´s the > > general idea in my code: > > > <div metal:define-macro="main" tal:define="x python:0"> > > > <tal:block tal:define="x python:x + 1"> > > <td> > > <input type="hidden" tal:attributes="value item/name; name > > python:'item_name_' + `x`"> > > > > Now, all of that works...once. That is, it increments from 0 to > 1, but > not from 1 to 2! Each time I pass through the td element, I > need it to > increment. I tried putting the tal definition in the td, > but then it > didn´t even increment once! What do? > > TIA, > > Tony > > ------------------------------------------------------------------------ > > AOL now offers free email to everyone. Find out more about what's > free > from AOL at *AOL.com* > <http://www.aol.com?ncid=AOLAOF00020000000437 > <http://www.aol.com/?ncid=AOLAOF00020000000437>>. > > > > > ------------------------------------------------------------------------ > > > _______________________________________________ > > Zope maillist - Zope@zope.org <mailto: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 ) > > -- Peter Bengtsson, > work www.fry-it.com <http://www.fry-it.com/> > home www.peterbe.com <http://www.peterbe.com/> > hobby www.issuetrackerproduct.com <http://www.issuetrackerproduct.com/> > ------------------------------------------------------------------------ AOL now offers free email to everyone. Find out more about what's free > from AOL at *AOL.com* <http://www.aol.com?ncid=AOLAOF00020000000437>. -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
________________________________________________________________________ AOL now offers free email to everyone. Find out more about what's free from AOL at AOL.com.
Use ZPT repeat variables ( http://www.plope.com/Books/2_7Edition/AdvZPT.stx#2-3). 2007/7/30, Peter Bengtsson <peter@fry-it.com>:
You can use the ZTUtils Iterator()
<div tal:define="iter python:modules['ZTUtils'].Iterator(range(1000))"> <br tal:define="dummy iter/next" tal:replace="iter/number" /> <br tal:define="dummy iter/next" tal:replace="iter/number" /> <br tal:define="dummy iter/next" tal:replace="iter/number" /> </div>
Which might give you some freedom such as iter/Roman or iter/odd The above is practically the same as:
<br tal:repeat="i python:range(3)" tal:replace="i" />
Generally, if you can, use a Python Script or something. The Iterator is/was used in Plone templates to increment the tab index.
tonylabarbara@aol.com wrote:
Hi; I´m trying to increment a variable in a page template. Here´s the general idea in my code:
<div metal:define-macro="main" tal:define="x python:0">
<tal:block tal:define="x python:x + 1"> <td> <input type="hidden" tal:attributes="value item/name; name python:'item_name_' + `x`">
Now, all of that works...once. That is, it increments from 0 to 1, but not from 1 to 2! Each time I pass through the td element, I need it to increment. I tried putting the tal definition in the td, but then it didn´t even increment once! What do? TIA, Tony ------------------------------------------------------------------------ AOL now offers free email to everyone. Find out more about what's free from AOL at *AOL.com* <http://www.aol.com?ncid=AOLAOF00020000000437>.
------------------------------------------------------------------------
_______________________________________________ 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 )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com _______________________________________________ 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 (5)
-
Andreas Jung -
Andrew Milton -
José Henrique -
Peter Bengtsson -
tonylabarbara@aol.com