Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
In TPL:Accessing an item without knowing it's name
marcmundt
In my TPL, I need to iterate through an "or" list of replicants. Since it's an "or", each iteration will, presumeably, be a different type of replicant item. How can I determine, as I'm iterating through, what type of replicant I'm dealing with?
The DCT snippet is conceptually like this:
<item name="the_replicant_in_question">
<replicant combination="or">
<item name="item_type_1" />
<item name="item_type_2" />
</replicant>
</item>
As I'm iterating, I need to find out if the current replicant item is an "item_type_1" or an "item_type_2" so I can deal with it properly (in my actual template, "item_type_1" is actually a container with a bunch of sub-items).
Is there a notation for "first occuring child element of the current replicant iteration"? And if so, is there a way to determine the name/type of said "first occuring child element"?
Thanks,
Marc
Find more posts tagged with
Comments
Gerard
I'm struggling with the same issue. Can somebody please give us an example of the corresponding Presentation Template logic??
I've tried to use the defined function, something like:
foreach my $replicant_item (iwpt_dcr_list('dcr.the_replicant_in_question'))
{
if (defined iwpt_dcr_value('replicant_item.item_type_1') )
{
}
else #item_type_2
{
}
} #end foreach
But this did not work.
Gerard.
Edited by Gerard on 08/07/02 05:15 AM (server time).
Migrateduser
I wrote some code to do this about six months ago, but I can't find it right now. I can give you the basic overview of what you need to do though -
1)The accessor syntax for iw_value, iw_iterate, etc. is basically like XPath except it is DCR-aware. So, if you need to peek further down than one level you can.
2)The DCRnode module (which should already be in your namespace in a PT), has a type method to determine the type and a get_node method to get the node.
What I don't remember off the top of my head is whether this will work:
<iw_iterate var='a' name='dcr.foo'>
<iw_if expr='($a->get_type eq "foo-sub1")'>
<iw_then>
<![CDATA[
some stuff
]]>
</iw_then>
<iw_else>
<![CDATA[
other stuff
]]>
</iw_else>
</iw_if>
</iw_iterate>
will work directly, or whether you have to do an iw_perl block to get the list of nodes and then iterate over them inside some iw_perl. I think the above PT is basically sound... but you might have to play with it a bit to get it to actually work. If I get a chance I'll try to find my code from when I did this and post it.
Cheers,
Rob Huffstedtler
rob@bagpipe.com
manju166
here is another example
it works for me..............
<iw_iterate list='dcr.Item' var='Item'>
<iw_if expr="{iw_value name='Item.Header Url'/} ne ''">
<iw_then>
<![CDATA[<p style="padding-bottom: 10"><a href="<iw_value name='Item.Header Url'/>"><iw_value name='Item.Header Name'/></a></p>]]>
</iw_then>
<iw_else>
<![CDATA[<p style="padding-bottom: 10"><iw_value name='Item.Header Name'/></p>
</iw_else>
</iw_if>
marcmundt
I found a quick/dirty workaround for this, so I stopped following the thread, but in case the workaround is still useful to anyone, I thought I'd post it.
Here's an example of TPL code. See below for the getChildNode and getNodeType functions.
Basically, I'm cheating by using the current iterant's inner xml:
-Get the inner xml for the current iterant
-Get the type of the first tag contained in the inner xml
-Use the type to get a reference to that first child node
<iw_iterate list='dcr.questions' var='replicant'>
<iw_perl>
<![CDATA[
$questionnode = &getChildNode($replicant);
$questionnodetype = &getNodeType($questionnode);
]]>
</iw_perl>
<![CDATA[
<p>
{iw_value name="questionnode.some_field_to_output"/}
</p>
]]>
</iw_iterate>
And here are the getChildNode and getNodeType functions:
sub getChildNode {
my $nodereference = $_[0];
my $nodexml = $nodereference->get_inner_xml();
$nodexml =~ m|^<([^>]*)>|;
my $nodetype = $1;
my $childnode = $nodereference->get_node($nodetype);
return $childnode;
}
sub getNodeType {
my $nodereference = $_[0];
my $nodetype = $nodereference->type();
return $nodetype;
}