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)
Help with simple IF Then statement
iwcnb
I am having a problem writing a simple IF THEN statement that compares a date in the text field to Today's date. I tried using a variable to assign Today's date after the equal operation, but it seems like I am not allow to do that. Here is my script:
<iw_perl><![CDATA[
sub DateTime{
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $date = sprintf("%2.2d/%2.2d/%4.4d ",$mon+1,$mday,$year+1900);
}
]]></iw_perl>
<iw_if expn='{iw_value name="Headline.Date"/} eq "$date" '>
<iw_then>
<![CDATA[<img src="/images/NewToday.gif" width="1" height="1" border="0" alt="">]]>
</iw_then>
</iw_if>
Is what I am doing correct or I missed something here.
Greatly appreciate if someone can show me a work around.
Thanks!
Find more posts tagged with
Comments
Migrateduser
I think there may be a couple of problems here? $date is only being populated inside the subroutine - so it should be local to that sub and not visible outside? And the sub is never being called? Plus don't you want dcr.Headline.Date (I am not sure).
<iw_perl><![CDATA[
sub DateTime
{
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
return( sprintf("%2.2d/%2.2d/%4.4d ",$mon+1,$mday,$year+1900));
}
my ${date} = DateTime();
...
<iw_if expn='{iw_value name="dcr.Headline.Date" /} eq {iw_value name="${date}" /}'>
iwcnb
John,
I use your version of the script but I still did not get it to work. I did not get any error. If I hardcode the value Today's date (02/28/2003) in place of the ${date} then it work. But placing the variable ${date} as the value did not work at all.
Also, the reason I did not have "dcr.Headline.Date" is that the IF statement is with an <iw_iterate> tag.
Any ideas?
Migrateduser
Can you post or email the DCT and TPL?
Adam Stoller
<font color='brown'>If I hardcode the value Today's date (02/28/2003) in place of the ${date} then it work. But placing the variable ${date} as the value did not work at all.</font>
I think the quoting is wrong in the example that was posted - the outer-most quotes should be double-quotes (") not single-quotes (') - otherwise the variables within will not be interpolated. So I think what's happening is that you're comapring the date from the DCR with the literal string "${date}" instead of its value.
--fish
(Interwoven Senior Technical Consultant)
iwcnb
John - Here is my DCR and TPL.
<?xml version="1.0" standalone="no"?>
<!DOCTYPE datacapture SYSTEM "datacapture5.0.dtd">
<data-capture-requirements type="content" name="Headlines">
<!-- data-capture-requirements elements contain area elements -->
<ruleset name="Info Headlines">
<description>
InfoLink Home Page Headlines
</description>
<item name="Headline">
<label>Headlines</label>
<replicant default="1" min="1" max="10">
<item name="Date">
<description>Date format is MM/DD/YYYY.</description>
<text required="t" maxlength="10" validation-regex="^[0-1][0-9]/[0-3][0-9]/[0-9][0-9][0-9][0-9]$" />
</item>
<item name="HeadlineText">
<textarea cols="82" rows="15" wrap="virtual" external-editor="visualformat" external-editor-inline="t" />
</item>
</replicant>
</item>
</ruleset>
</data-capture-requirements>
TPL:
<?xml version="1.0" encoding="UTF-8"?>
<iw_pt name="Headlines">
<![CDATA[
<%
dim strdate
strDate = date()
function FixDate(strDate)
dim NewDate,TodaysDate
NewDate = strDate
if instr(left(NewDate,2),"/") then
NewDate = "0" & NewDate
end if
if mid(NewDate,5,1) = "/" then
NewDate = left(NewDate,3) & "0" & mid(NewDate,4)
end if
FixDate = NewDate
end function
'TodaysDate = FixDate(strDate)
'response.write TodaysDate
%>
<html>
<head>
<title>Announcements</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellspacing="1" cellpadding="1" vspace="4">]]>
<iw_perl><![CDATA[
sub DateTime
{
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
return( sprintf("%2.2d/%2.2d/%4.4d ",$mon+1,$mday,$year+1900));
}
my ${date} = DateTime();
]]></iw_perl>
<iw_iterate list='dcr.Headline' var='Headline'>
<![CDATA[<tr>
<td valign="top">]]>
<iw_if expn='{iw_value name="Headline.Date"/} eq {iw_value name="${date}" /} '>
<iw_then>
<![CDATA[<img src="/images/new.gif" width="61" height="12" border="0" alt="">]]>
</iw_then>
</iw_if>
<![CDATA[<iw_value name="Headline.HeadlineText"/></td>
</tr>
<tr>
<td height="5"><img src="/images/dot.gif" width="1" height="1" border="0" alt=""></td>
</tr>
]]>
</iw_iterate>
<![CDATA[ </table>
</body>
</html>]]>
<!-- End CDATA tag -->
</iw_pt>
iwcnb
ghoti - base on the code that I have could you fix the code and provide the correct syntax?
Migrateduser
I think I found the answer to your problem.
Just after my ${date} = DateTime();, add another line chop($date);
What was happening is that there was a whitespace in $date in the end and so the comparison was failing.
Thanks
Migrateduser
Btw, does anybody know what happened to iwpt_output? There is no reference to this particular IW tag in the Templating Developers Guide. I have used it in older versions but haven't tested to see if it works in 5.5.2
Streamshare.zip
iwcnb
Saran,
I don't quite understand what you mean by line chop($date);? Could you provide an example?
thanks!
Migrateduser
chop - Chops off the last character of a string
$xyz = "abcd";
chop($xyz);
print "$xyz";
will print "abc" because the last character gets chopped.
I'm actually talking about some way to 'trim' as in other languages. I'm not a perl expert and this is one way I know how to do it, I hope it's right, if not some Perl gurus help us!
So, instead of
<iw_perl><![CDATA[
sub DateTime
{
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
return( sprintf("%2.2d/%2.2d/%4.4d ",$mon+1,$mday,$year+1900));
}
my ${date} = DateTime();
]]></iw_perl>
if you have
<iw_perl><![CDATA[
sub DateTime
{
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
return( sprintf("%2.2d/%2.2d/%4.4d ",$mon+1,$mday,$year+1900));
}
my ${date} = DateTime();
chop($date);
]]></iw_perl>
then for example "03/03/2003 " gets chopped to "03/03/2003" and the comparison will succeed.
Hope this helps now.
Migrateduser
Hmmm.. you know what, I was wondering why we have a whitespace in the first place. It's because you have this
my $date = sprintf("%2.2d/%2.2d/%4.4d ",$mon+1,$mday,$year+1900);
Instead, if you had
my $date = sprintf("%2.2d/%2.2d/%4.4d",$mon+1,$mday,$year+1900);
there would not have been any problem. So, forget about chop!
Thanks
Adam Stoller
iwpt_output is not a tag - it is a method available within iw_perl to send output to the right place (you should use this instead of 'print')
--fish
(Interwoven Senior Technical Consultant)