Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
iw_itereate counter
Satan
I'd like to code an iw_if statement that keeps track of how many iterations of a replicant there are. For example, if this is the first time through the iteration loop, then start a new TR, if it's the second, start a new TD, if it's the third, start a new TD and close the TR, etc.
any thoughts?
thanks
Find more posts tagged with
Comments
Migrateduser
before the iw_iterate put an iw_perl that initializes a counter variable. Inside the iw_iterate use an iw_perl to increment the variable.
Maybe there is a cleaner way.
Satan
That sounds pretty clean, actually. Can you point me to a resource for the needed Perl code?
thanks!
Migrateduser
If you are not using loose presentation templates you should. Otherwise you should put the opening and closing CDATA things. I don't have time for the Perl and I;m sure someone else could do a better job of this but it might look something like:
<iw_perl><![CDATA[
my ${counter} = 0;
]]></iw_perl>
<iw_iterate [whatever]>
<iw_perl><![CDATA[
my ${html} = "";
if ( some condition on ${counter} )
{
${html} = whatever;
}
elsif ( some other condition on ${counter} )
{
${html} = whatever;
}
iwpt_output( ${html} );
]]</iw_perl>
</iw_iterate>
Veneet_Kumar
Hi all, my query is related to the counter problem. I have the following HTML block that I need to iterate::
menu_content = new Array('<a href="
http://www.google.com"class=subMenu>google
tool bar </a> |<a href="
http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=&btnG=Google+Search"class=subMenu>google
search </a> |',
'<a href="
http://www.abc.com"class=subMenu>ABC
Menu Name </a> |<a href="
https://www.utlimatix.net"class=subMenu>ABC
New Menu </a> |',
'<a href="
http://www.indiatimes.com"class=subMenu>indiatimes
Cricket </a> |<a href="
http://www.email.indiatimes.com"class=subMenu>Indiatimes
Email </a> |');
For generating this repititive HTML, i am using the following Presentation template code ::
menu_content = new Array(
]]>
<iw_iterate var='menu_name' list='dcr.MenuHeading'>
<![CDATA[']]>
<iw_perl>
<![CDATA[$m=0;]]>
</iw_perl>
<iw_iterate var='menu_link' list='menu_name.MenuItem'>
<iw_perl>$m++;</iw_perl>
<![CDATA[ <a href="<iw_value name='menu_link.MenuItemURL'/>"]]><![CDATA[class=subMenu>]]><iw_value name='menu_link.MenuItemName'/><![CDATA[ </a> |]]>
</iw_iterate><![CDATA[',]]>
</iw_iterate><![CDATA[);
Now the probs is that using this code, the HTML gets generated, but the ,(comma) in the line (</iw_iterate><![CDATA[',]]>) creates problem due to which I can get the correct output. I do not need that comma in the last iteration. For this I need to know by how much my counter wud iterate before hand, so that I can put the other format in some if condition. Can anybody give some idea on this?
Thanks
akshathp
Two options I could think of are:
1. You could have one more iterate block inserted before this iterate. I mean, the dummy one will parse through all replicant values and create a counter variable for you.
2.
<iw_perl>
<![CDATA[
my
@list
= iwpt_dcr_list('dcr.a.b');
my $ctr = scalar(
@list)
;
iwpt_output($ctr);
]]>
</iw_perl>
Ofcourse, replace a and b with your replicant item names. And at the end ctr variable can be used in the main iterate block tha tyou have with iw_if tag.
Hope this helps!
Akshat Pramod Sharma
pflory
Here's an idea simlar to akshat's:
1) first, use <iw_perl> to get/set the number/list of elements to iterate over. E.g.,
<iw_perl><![CDATA[
my
@names
= iwpt_dcr_list('dcr.names');
my
@list
= (0 .. $#names );
]]>
</iw_perl>
2) then iterate over the list, accessing the container/replicant items by index:
<iw_iterate var="index" list='(
@list)
'>
<iw_value name='dcr.names[$index].firstName'/>
....
-Paul
http://www.clusterballoon.org/cluster1.htm
Paul Flory
http_submit_runtime_settings.gif
http_response_connector_settings.gif
haplo
just to say that first there is the "iteration" option in the iw_iterate that retain the number of the current iteration
<iw_iterate var="variable" list="dcr.brol" iteration="current_iteration_number">
<iw_value name="current_iteration_number"/>
</iw_iterate>
And for your problem that you you don't want the , in the last iteration you can reverse the display...let me explain...
<iw_iterate var="variable" list="dcr.brol" iteration="current_iteration_number">
<iw_if expr='{$current_iteration_number != 0 }'>
<iw_then>
iwpt_output(',');
</iw_then>
</iw_if>
display what you want here
</iw_iterate>