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)
iw_ifcase in Perl
cvel2
I am trying to parse a combination-or replicant in my presentation template. The only way that I have found to do this is by using the presentation template tags, however, I would like to try this using Perl....is this possible?
This is the code I have so far and it returns to node, but not the node type.
foreach my $paragraph_replicant(iwpt_dcr_list('dcr.article_content.article_paragraph')){
if ($paragraph_replicant eq "text_only"){
iwpt_output ("text only\n");
}
elsif ($paragraph_replicant eq "text_with_image"){
iwpt_output ("text_with_image\n");
}
elsif ($paragraph_replicant eq "image_only"){
iwpt_output ("image only\n");
}
}
Find more posts tagged with
Comments
Adam Stoller
See if
this post
answers your question.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
cvel2
Fish,
That didn't seem to work.
While it would be nice to do this in Perl, at this point in time, I just want to get the values of the combination-or replicant ANY way. I have looked at all of the posts on DevNet, referred to the documentation, and I cannot find anything that seems to work. If someone could please help me, I'd be MUCH appreciative and you would likely save my sanity
I have tried the following which seems to follow everything I've seen (Note: I've tried this in addition to many other variations of this, and the Perl you gave me):
<iw_iterate var="node" list="dcr.article_content.article_paragraph.*">
<iw_ifcase name="node">
<iw_case type="paragraph_text">
<iw_perl><![CDATA[iwpt_output ("text only\n");]]></iw_perl>
</iw_case>
<iw_case type="text_with_image">
<iw_perl><![CDATA[iwpt_output ("text_with_image\n");]]></iw_perl>
</iw_case>
<iw_case type="image_only">
<iw_perl><![CDATA[iwpt_output ("image only\n");]]></iw_perl>
</iw_case>
</iw_ifcase>
</iw_iterate>
And this will only return the first value in the list (there are three). If I move the replicants up or down in the list, it will still only display the first item.
Here is the code in the DCR for the replicant that I am trying to return the values for.
<item name="article_paragraph">
<label>Paragraph</label>
<description>Please choose the type of paragraph you would like to add.</description>
<replicant combination="or" max="20" min="0">
<container name="text_only">
<label>Text Only</label>
<item name="paragraph_text">
<label>Paragraph Text</label>
<description>Launch Visual Format and type the paragraph text. Click 'Ok' when finished typing text to return to data capture form.</description>
<textarea cols="45" rows="2" wrap="virtual" required="t">
<cgi-callout url="/iw-bin/ict/compass_visual_format_callout.ipl/compass.cfg" label="Launch Visual Format" window-features="top=40,left=20,width=750,height 480,resizable=yes,toolbar=no,scrollbars=yes"/>
</textarea>
</item>
</container>
<container name="text_with_image">
<label>Text With Image</label>
<item name="image">
<label>Image</label>
<description>Browse to select an image from TeamSite or Upload an image from your local computer.</description>
<browser extns=".gif,.jpg" size="42" initial-dir="/images" required="t">
<cgi-callout url="/iw-bin/ICT/TheCompass/load.cgi" label="Upload Image" window-features="width=320,height=200,resizable=yes,toolbar=no,scrollbars=yes"/>
</browser>
</item>
<item name="image_alt_text">
<label>Image Alt. Text</label>
<description>Enter the text you would like to have appear when a user hovers the mousepointer over the image.</description>
<text size="55" required="t"/>
</item>
<item name="image_caption">
<label>Image Caption</label>
<description>Enter the text you would like to appear below the image.</description>
<text size="55"/>
</item>
<item name="image_caption_font">
<label>Image Caption Font</label>
<description>Please choose which font the image caption should appear in - bold or italic.</description>
<select>
<option label="---Please Select---" value="select" selected="t"/>
<option label="Bold" value="bold" selected="f"/>
<option label="Italic" value="italic" selected="f"/>
</select>
</item>
<item name="image_alignment">
<label>Image Alignment</label>
<description>Please where the image should appear.</description>
<select required="t">
<option label="---Please Select---" value="select" selected="t"/>
<option label="Right" value="right" selected="f"/>
<option label="Left" value="left" selected="f"/>
</select>
</item>
<item name="paragraph_text">
<label>Paragraph Text</label>
<description>Launch Visual Format and type the paragraph text. Click 'Ok' when finished typing text to return to data capture form.</description>
<textarea cols="45" rows="2" wrap="virtual" required="t">
<cgi-callout url="/iw-bin/ict/compass_visual_format_callout.ipl/compass.cfg" label="Launch Visual Format" window-features="top=40,left=20,width=750,height 480,resizable=yes,toolbar=no,scrollbars=yes"/>
</textarea>
</item>
</container>
<container name="image_only">
<label>Image Only</label>
<item name="image">
<label>Image</label>
<description>Browse to select an image from TeamSite or Upload an image from your local computer.</description>
<browser extns=".gif,.jpg" size="42" initial-dir="/images" required="t">
<cgi-callout url="/iw-bin/ICT/TheCompass/load.cgi" label="Upload Image" window-features="width=320,height=200,resizable=yes,toolbar=no,scrollbars=yes"/>
</browser>
</item>
<item name="image_alt_text">
<label>Image Alt. Text</label>
<description>Enter the text you would like to have appear when a user hovers the mousepointer over the image.</description>
<text size="55" required="t"/>
</item>
<item name="image_caption">
<label>Image Caption</label>
<description>Enter the text you would like to appear below the image.</description>
<text size="55"/>
</item>
<item name="image_caption_font">
<label>Image Caption Font</label>
<description>Please choose which font the image caption should appear in - bold or italic.</description>
<select>
<option label="---Please Select---" value="select" selected="t"/>
<option label="Bold" value="bold" selected="f"/>
<option label="Italic" value="italic" selected="f"/>
</select>
</item>
<item name="image_alignment">
<label>Image Alignment</label>
<description>Please where the image should appear.</description>
<select required="t">
<option label="---Please Select---" value="select" selected="t"/>
<option label="Right" value="right" selected="f"/>
<option label="Left" value="left" selected="f"/>
</select>
</item>
</container>
</replicant>
</item>
Adam Stoller
Could you attach a full DCR (so I don't have to try and re-create it) - if so, I'll see if I can figure out the PT part.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
cvel2
Sure.
Here it is (as a text file)
Edited by cvel2 on 04/02/04 06:52 AM (server time).
Adam Stoller
Okay - try this:
<iw_pt name="testing"/>
<iw_perl>
my $dcr = iwpt_get_dcr_name();
my $xml = '';
if (open(IN, "<$dcr")){
local $/;
$xml = <IN>;
close(IN);
}
use TeamSite::XMLnode;
my $rootnode = TeamSite::XMLnode->new($xml);
my
@list
= $rootnode->get_node_list('article_content.article_paragraph');
foreach my $node (
@list){
foreach ($node->get_node_list()){
my $type = $_->type();
if ($type eq "text_only"){
iwpt_output("This is Text Only\n");
}
elsif ($type eq "text_with_image"){
iwpt_output("This is Text With Image\n");
}
elsif ($type eq "image_only"){
iwpt_output("This is Image Only\n");
}
}
}
</iw_perl>
I'm not sure of the exact translation into XML format - but I think the key is that you have to have nested iterations - the first iteration only gives you article_paragraph elements, not the sub-elements within the article_paragraph node.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
JonathonG
(Note: cvel2 is one of my co-workers on my current project, so I've been trying to get this to work as well)
Interestingly, I came up with something very similar. I guess great minds really do think alike
What's fun is that the return from iwpt_dcr_list is actually an array of TeamSite:
CRnode objects. So, you don't have to have the stuff about reading/parsing the XML. You can access the node object methods from its return. So, everything in your iwperl tag up to and including this line:
my
@list
= $rootnode->get_node_list('article_content.article_paragraph');
can be replaced with this one line (assuming you're already in a PT):
my
@list
= iwpt_dcr_list('dcr.article_content.article_paragraph');
Jonathon
Independent Interwoven Contractor
Adam Stoller
Doh! Of course - I've done so much of this stuff for things like externaltask scripts in workflows where I'm not using a PT that I forgot I already have the handle to pull from within the PT.
Thanks for pointing that out.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
Adam Stoller
FYI - I believe this is the XML equivalent:
<iw_pt name="testing"/>
<iw_iterate var="node" list="dcr.article_content.article_paragraph">
<iw_iterate var="item" list="node.*">
<iw_ifcase name="item">
<iw_case type="text_only">
This is Text Only
</iw_case>
<iw_case type="text_with_image">
This is Text With Image
</iw_case>
<iw_case type="image_only">
This is Image Only
</iw_case>
</iw_ifcase>
</iw_iterate>
</iw_iterate>
I tend to prefer the Perl approach which, if for no other reason, doesn't insert as many blank lines in the output - though you could format the above XML code like this:
<iw_pt name="testing"/>
<iw_iterate var="node" list="dcr.article_content.article_paragraph"><iw_iterate var="item" list="node.*"><iw_ifcase name="item">
<iw_case type="text_only">This is Text Only
</iw_case><iw_case type="text_with_image">This is Text With Image
</iw_case><iw_case type="image_only">This is Image Only
</iw_case></iw_ifcase></iw_iterate></iw_iterate>
and achieve the same result - I just find the Perl code cleaner and easier to deal with.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com