Gossamer Forum
Home : Products : Links 2.0 : Customization :

<%if%> testing

Quote Reply
<%if%> testing
Take a look at the code below. It's the standard if-testing used by Links 2.0. Is there a logical "or" operator I can use? I want to say if thing1 or if thing2.

Code:
<%if prev%>
some code here
<%endif%>
Any help is greatly appreciated!

Ryan

Quote Reply
Re: <%if%> testing In reply to
The 'else' tag for that would be <%ifnot prev%>. If you install the enhanced templates.pm mod you can do cooler conditionals without adding any perl coding:

<%if this eq 'that'%>
Do something special.
<%endif%>
<%if this eq 'something'%>
Do something else.
<%ifnot this%>
Do the default.
<%endif%>

This gives you something like 'elsif' and 'else'.

--Drew
Quote Reply
Re: <%if%> testing In reply to
I think you missed my point I want to say something like...

<%if prev or if next%>
code here
<%endif%>

How can I do that?

Quote Reply
Re: <%if%> testing In reply to
Guess so... You would actually have to add 'or' and '||' operations into templates.pm in a similar manner as the other equality operators. That would be an interesting modification and I hope someone comes up with a solution.

--Drew
Quote Reply
Re: <%if%> testing In reply to
Huh, it's too bad templates.pm doesn't support an "or" operator! As flexible as Links has been for me I can't believe this isn't possible.

I guess I'll take a look at templates.pm and try to hack it. If anyone else would make an attempt too that would be great.

Later... Ryan

Quote Reply
Re: <%if%> testing In reply to
Of course...you could use the following codes in the sub site_html_link routine:

Code:

if (($rec{'Fieldname'} eq "something") or ($rec{'Fieldname'} eq "somethingelse")) {
$fieldname = qq|Some HTML codes|;
}
else {
$fieldname = qq|Some Other HTML codes|;
}


Then define the following tag:

Code:

fieldname => $fieldname


in the same subroutine.

Then in your link.html template file, use the following tag:

Code:

<%fieldname%>


Pay close attention to the EXACT case settings that I have used in the above example.

Regards,

Eliot Lee

Quote Reply
Re: <%if%> testing In reply to
That could work... but optimally, I think what we're looking for is really a globally accessible operator like 'eq', 'gt', 'lt', etc, as opposed to predefined comparisons.

--Drew
Quote Reply
Re: <%if%> testing In reply to
In Reply To:
That could work...
Uh...it will work. Wink

In Reply To:
I think what we're looking for is really a globally accessible operator like 'eq', 'gt', 'lt', etc, as opposed to predefined comparisons.
From the Enhanced Template.pm Codes Mod....

In Reply To:
You can use the following operators for comparision: eq, =, lt, gt, >, <.
The problem is with OR...but the other operators you mention already work in templates (if you download and install the Enhanced Template.pm Mod. Wink

Regards,

Eliot Lee


Quote Reply
Re: <%if%> testing In reply to
Let me clarify if you're going to be picky about my 'coulds, woulds, shoulds, cans and wills'...

In Reply To:
That could work...
...just fine and dandy if you only have one case in which you need an 'or', and if links.html is where you need it.

In Reply To:
but the other operators you mention already work in templates
That's what I was implying.

Ugh... I'm working toward a degree in information systems technology, not grammer, Eliot. Smile

--Drew
Quote Reply
Re: <%if%> testing In reply to
Ok, I am at almost at a point of understand. Instead of having one fieldname I need two. And rather than checking to see if they equal something, I just need to check if they are there. Here is what I have in my category.html right now:

Code:
<%if prev%>
some text
<%prev%>
some text
<%endif%>

<%if next%>
some text
<%next%>
some text
<%endif%>
Anthro, I understand I need to add code in site_html_templates.pl, but what do I need to add to achieve this affect I have outlined below?

Code:
<%if prev or if next%>
some text
<%prev%>
<%next%>
some text
<%endif%>
Thanks, Ryan

Quote Reply
Re: <%if%> testing In reply to
Read the codes I posted MORE carefully! The conditional statements are DEFINED in the sub site_html_link routine in the site_html_templates.pl (repeating myself)...And you simply use the <%fieldname%> tag in the link.html file.

Do you understand it now or shall I draw a diagram? Wink

Regards,

Eliot Lee

Quote Reply
Re: <%if%> testing In reply to
In the first line of code you posted in red... I would want it to read like this??


if (($rec{'Fieldname'} eq "prev") or ($rec{'Fieldname'} eq "next")) {


Quote Reply
Re: <%if%> testing In reply to
Yes...but I think that you are trying to use conditional statements with the span codes for result pages, which means that the codes in the sub build_category_pages in the nph-build.cgi and sub site_html_category in the site_html_templates.pl...

The example I've provided is for fields within your links.db file that you set certain conditions NOT with variables defined in subs in the various LINKS scripts.

Regards,

Eliot Lee

Quote Reply
Re: <%if%> testing In reply to
Yes, I am trying to use conditional statements with the span codes. Can you show me how?