Gossamer Forum
Home : Products : Links 2.0 : Customization :

If Yes, do this - if No, do that

Quote Reply
If Yes, do this - if No, do that
I have a Yes/No field, and would like to show different things depending on its value.

Surely this must be possible? Or?

Quote Reply
Re: If Yes, do this - if No, do that In reply to
Well, it's for a customised thing, in Danish, so in order not to explain - and confuse - too much, let's just say I wanted to output different things for, say, the isNew, which, as you know, also uses Yes/No.

<%if isNew%>
This is new!
<%endif%>

But if I wanted it to say "This is not new" if isNew isn't new (ie., is No), what then?

Hope this clarifies what I want.

Hmmm ... come to think of it, maybe I don't want to use a Yes/No field then??
Quote Reply
Re: If Yes, do this - if No, do that In reply to
You'd need to install the Nested Ifs mod from the resource center. Then you put code in your template like:
Code:
<%if isNew%>
This is new!
<%ifnot isNew%>
This is not new!
<%endif%>

And you'll need to add to site_html_templates.pl a line like Bobsie describes for isPopular in this thread: http://www.gossamer-threads.com/...um3/HTML/002126.html

Hope this helps
Phoenix
Quote Reply
Re: If Yes, do this - if No, do that In reply to
Hmmm ... I do have the nested mod installed, but thought it wasn't ifnot I wanted -- doesn't that look for empty fields??

Phoenix, do you mean the
Quote:
if (! $rec{'isPopular'} eq 'Yes') {
delete $rec{'isPopular'};
}
part?? (note my message in the other thread about brackets).

This does not work. (and I have changed to my field name)

Also, for the record, don't you need endif's for each if/ifnot?? Is your code correct? (I thought you needed two endifs....

Confused :-(

John

[This message has been edited by gotze (edited July 04, 1999).]

[This message has been edited by gotze (edited July 04, 1999).]
Quote Reply
Re: If Yes, do this - if No, do that In reply to
Yes, it is possible. So what is it you want to show and where? If you need help, you need to explain.
Quote Reply
Re: If Yes, do this - if No, do that In reply to
John,

Yes, that's exactly the part I mean. You'd have:
Code:
if (! $rec{'YourField'} eq 'Yes') {
delete $rec{'YourField'};
}
What this does is in temporary memory, delete the contents of that field if it finds anything other than Yes in the field. If the word No is in your field, it will simulate a balnk field, so that you can use if and ifnot statements. It should be put in site_html_templates.pl in the links section. (Detailed as well, if you are using detailed pages.)

My example of how to use the if and ifnot statements, though, is from an older version of the Nested Ifs mod. I'm not sure if the syntax is correct for that part in the currect version. I only know that in the original version of this mod, if and ifnot were part of one statement, so I only had to use one <%endif%>. Play around with that... that might be the part that's incorrect.

Phoenix



[This message has been edited by phoenix (edited July 04, 1999).]
Quote Reply
Re: If Yes, do this - if No, do that In reply to
Come to think of it, maybe Bobsie's code is incorrect here. I just looked at the site_html_templates.pl, and it looks like this is what you'd want:
Code:
($rec{'YourField'} eq 'Yes') ? ($rec{'YourField'} = 1) : (delete $rec{'YourField'});

Sorry for adding confusion, but I think this is the code you'd want in site_html_templates.pl

Phoenix
Quote Reply
Re: If Yes, do this - if No, do that In reply to
Phoenix,

By golly, I think you are right! For some reason, I was thinking that <%if ...%> and <%ifnot ...%> were checking to see if a variable existed. Instead, they are checking for a true or false value. So, the variable would have to be set to "1" to be true, otherwise, it would be false.

I stand corrected and thank you for pointing out the error of my ways! Smile

[This message has been edited by Bobsie (edited July 05, 1999).]
Quote Reply
Re: If Yes, do this - if No, do that In reply to
Bobsie,

Yep, that's clear. I was just not sure, so I wanted to cover all the bases. Smile Thanks for the clarification.

Phoenix
Quote Reply
Re: If Yes, do this - if No, do that In reply to
Umm, in case you hadn't noticed... the clarification went away (i edited the message). You were right and I was wrong, so there was no need for me to clarify it. You clarified it to me after I relooked at the issue again.
Quote Reply
Re: If Yes, do this - if No, do that In reply to
Ah, gee I was right and I didn't even know why. Smile How like me! I'm sort of playing "pin the tail on the donkey" with PERL... every so often I get one.

Phoenix
Quote Reply
Re: If Yes, do this - if No, do that In reply to
Thanks Phoenix and Bobsie!

I got it to work now :-)

For the record:

Each if needs to be closed, so the code is like this:
Quote:
<%if isNew%>
This is new!
<%endif%>
<%ifnot isNew%>
This is not new!
<%endif%>
Otherwise it breaks the HTML.

One day I'll try and write this into the FAQ.

John

[This message has been edited by gotze (edited July 05, 1999).]
Quote Reply
Re: [gotze] If Yes, do this - if No, do that In reply to
In Reply To:
Thanks Phoenix and Bobsie!

I got it to work now :-)

For the record:

Each if needs to be closed, so the code is like this:
Quote:
<%if isNew%>
This is new!
<%endif%>
<%ifnot isNew%>
This is not new!
<%endif%>
Otherwise it breaks the HTML.

One day I'll try and write this into the FAQ.

John

[This message has been edited by gotze (edited July 05, 1999).]
I am still having problems with this... could you help please?

SITE_HTML_TEMPLATES.PL

...
sub site_html_detailed {
# --------------------------------------------------------
# This routine will build a single page per link. It's only
# really useful if you have a long review for each link --
# or more information then can be displayed in a summary.
#

my %rec = @_;
my $temp = $rec{Category};$temp =~ s/_/ /;($rec{Country}, $rec{State}, $rec{City}) = split /\//, $temp;

#### IFNOT MOD START
if (! $rec{'Graphic'} eq '1') {
delete $rec{'Graphic'};
}
#### IFNOT MOD END

return &load_template ('detailed.html', {
total => $total,
grand_total => $grand_total,
title_linked => $title_linked,

%rec,
%globals
} );

}
...


DETAILED.HTML


...
<%if Graphic%>
<img src="<%Graphic%>">
<%endif%>
<%ifnot Graphic%>
No Photo
<%endif%>
...

Thanks,

Will
Quote Reply
Re: [WTrippe] If Yes, do this - if No, do that In reply to
>>if (! $rec{'Graphic'} eq '1') {<<

That makes no sense. It must either be:

if ($rec{'Graphic'} == 1) {

or

if (! $rec{'Graphic'}) {
Quote Reply
Re: [PaulW] If Yes, do this - if No, do that In reply to
You forgot to put this:

Graphic => $Graphic,