Home
TeamSite
iw_iterate
Wackie
Hi,
Does iw_iterate support a counter?
It would be really usefull if I could include a counter that increments each time the iw_iterate loops.
I've seen some code which includes a iteration attribute: (see below)
When I use {iw_value name='counter'/} it always returns zero for each loop.
Can anyone help? Am I using the right code??
Thanks
Steve
Find more posts tagged with
Comments
Wackie
Sorry, code attached below.
<iw_iterate var="xc" list="x.ManyPics" iteration="counter">
Adam Stoller
RTFM -
http://your-server/iw/help/tst/pt/TeamSite__PT__iw_iterate.html
in there you'll see an example using the iteration parameter - and you'll see the syntax used for referencing it within an iw_if expression.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
perryjas
HI,
Thanks for the link, I'm new to Teamsite and did not know of the help files.
I've followed the help page but I am still getting 0's for all iterations. Here is a snipet of code
<iw_iterate var='xc' list='x.ManyPics' iteration='counter'>
<![CDATA[
<script language="javascript">var strCaption{iw_value name="$counter"/}="{iw_value name='xc.Caption'/}";</script>
]]>
</iw_iterate>
I add the $ to the counter in iw_value as per the help page, but its not incrementing still.
Can you help?
Adam Stoller
Someone else will have to pitch in here - I tend to do most of my PT coding in Perl rather than pseudo-XML - and I don't have time right now to play with this. Sorry.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
Michael
If you just want the value output into your resulting html/javascript then you could just use something like <iw_value name='current_color'/>. Use <...> instead of {....}.
The second type appear to be the syntax you use only when you are evaluating the values, such as in iw_if tags.
Hope this helps
Cheers
Michael
perryjas
Hi,
Tried changing the ()'s to <>'s but still no joy
Is there another way I can do this?
Steve
LooseCannon
What does does 'x' represent in: list='x.ManyPics'
If it's the xml file (dcr) then replace x with dcr: list='dcr.ManyPics'
]]>
<iw_iterate var='xc' list='dcr.ManyPics' iteration='counter'>
<iw_value name="$counter"/>
</iw_iterate>
<![CDATA[
perryjas
'x' is a var to the parent iw_iterate. <iw_iterate var="x" list="dcr.text">
The TPL works, it generates the page correctly. The page consists of text and images (thumbnails) and what I would like to do is show the full image in a pop-up window when the image or piece of text is clicked on. I decided to do this with javascript and give each image a unquie ID and name with this line going inside the iw_iterate loop.
<img name="rpic<iw_value name="$counter"/>" src="{iw_value name='xc.Picture'/}" border="0" align="" alt="<iw_value name='xc.Caption'/>" />
LooseCannon
is 'dcr.text.ManyPics' a replicant
Wackie
Yes, Manypics is a replicant
KTR
Could you pls post the attachments of DCT and TPL files, I did this kind of stuff and worked fine for me.
Thanks,
KT
Wackie
Thanks,
See attached file
Steve
KTR
Pls try with the following attachment. I never changed the DCT, but, did some changes on TPL code( especially on 'counter'). Let me know as soon you test this.
LooseCannon
I think your logic/code that displays the counter value is causing you problems not the logic/code that increments the counter.
I created a dct from your attachment and a simple tpl that display's the counter value. Works fine.
You need to simplify the code and start debugging
Wackie
KTR,
Thanks for the looking at the TPL, I tried it but it did not work, still 0's for each iteration.
LooseCannon,
Could you please attach the TPL you created, si I can compare your TPL and my TPL, hopefully it will show me where the errors are my TPL.
Thanks a lot
Steve
LooseCannon
Here is the tpl (if you view source on the attachment from my previous post you will find it as well). I created 3 ManyPics replicants.
<?xml version="1.0" encoding="UTF-8"?>
<![CDATA[
<html>
<body>
]]>
<iw_iterate var="x" list="dcr.text">
<iw_iterate var='xc' list='x.ManyPics' iteration='counter'>
<![CDATA[<p>COUNTER VALUE:<iw_value name="$counter"/></p>]]>
</iw_iterate>
</iw_iterate>
<![CDATA[
</body>
</html>
]]>
Adam Stoller
As an
FYI
- your PT's do not have to be well-formed XML - which allows you to get rid of all the CDATA tags and make the PT easier to read - so you can change this:
<?xml version="1.0" encoding="UTF-8"?>
<iwpt name="example"
>
<![CDATA[
<html>
<body>
]]>
<iw_iterate var="x" list="dcr.text">
<iw_iterate var='xc' list='x.ManyPics' iteration='counter'>
<![CDATA[
<p>COUNTER VALUE:<iw_value name="$counter"/></p>
]]>
</iw_iterate>
</iw_iterate>
<![CDATA[
</body>
</html>
]]>
</iwpt>
to this:
<iwpt name="example"/>
<html>
<body>
<iw_iterate var="x" list="dcr.text">
<iw_iterate var="xc" list="x.ManyPics" iteration="counter">
<p>COUNTER VALUE: <iw_value name="$counter"/></p>
</iw_iterate>
</iw_iterate>
</body>
</html>
This style of writing PT's has been available since TS 5.0.1 and
is
officially supported.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
Wackie
Sorry for not replying to you earlier.
Thanks the FYI. Most of the PT's were created a few years ago so they are all formatted as valid XML docs.
I've copied your example and I sill get four 0's being written to the screen.
<iw_iterate var="x" list="dcr.text">
<iw_iterate var="xc" list="x.ManyPics" iteration="counter">
<![CDATA[ Counter= <iw_value name='$counter'/> <br> ]]>
</iw_iterate>
</iw_iterate>
Migrateduser
Here is an example from some of my code. This is from a replicant.
<![CDATA[<modelDesc>]]><iw_value name='dcr.modelDesc'/><![CDATA[</modelDesc>]]>
<iw_iterate list='dcr.fileData' var='filedata'>
<iw_perl><![CDATA[
my $fileName = iwpt_dcr_value('dcr.fileData[$count].fileName');
my $fileType = iwpt_dcr_value('dcr.fileData[$count].fileType');
my $fileSize = iwpt_dcr_value('dcr.fileData[$count].fileSize');
my $downloadTime = iwpt_dcr_value('dcr.fileData[$count].downloadTime');
#my $fileDesc = iwpt_dcr_value('dcr.fileData[$count].fileDesc'); # called from below
$count=$count + 1;
]]></iw_perl>
<iw_iterate list='filedata.fileDesc' var='filedesc'>
<![CDATA[<fileDesc>]]><iw_value name='filedesc'/><![CDATA[</fileDesc>]]>
</iw_iterate>
</iw_iterate>
Wackie
Thanks,
I don't know Perl too well but your code did show me an approach I could use with ASP. Here is my code which now shows
Counter 0
Counter 1
Counter 2
Counter 3
Thanks for your help
<![CDATA[
<%
Dim intCounter
intCounter = 0
%>]]>
<iw_iterate var="x" list="dcr.text">
<iw_iterate var="xc" list="x.ManyPics" iteration="counter">
<![CDATA[<%
'Response.Write("Counter=" & intCounter & "<br>")
'intCounter = intCounter + 1
%>]]>
</iw_iterate>
</iw_iterate>