Gossamer Forum
Quote Reply
if clause
I'm having problem getting a simple if clause working in the detailed.html template.

I have one field that is a multi-select, and I want to be be able to do the following:

<%if options eq option1%> display option 1 <%endif%>
<%if options eq option2%> display option 2 <%endif%>
<%if options eq option3%> display option 3 <%endif%>

But if more than one option is selected in the multi-select, then nothing is displayed. The "if equal" clause only works if one option is selected.

Any ideas?
Quote Reply
Re: [joeybone] if clause In reply to
Mmm, its actually not as simple as you would expect. Really, what you need to do - is split the value up, and then loop it. For example (untested):

split_up_value
Code:
sub {
my @tmp = split /\n|\r/, $_[0];
return { value_split => \@tmp }
}

..then call with:

Code:
<%split_up_value($Field)%>
<%loop value_split%>
<%loop_value%> <br />
<%endloop%>

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] if clause In reply to
Andy, thanks for your help. Your solution works fine, but what I want to do is slightly more complicated.

The loop you suggested displays an array of the values, ie:

option1
option2
option3

I actually want those values to generate include files within a dynamic detailed page.

Something like this:

<%if options eq option1%>

<%LWP::Simple::get('http://domain.com/option1.html')%>

<%endif%>

<%if options eq option2%>

<%LWP::Simple::get('http://domain.com/option2.html')%>

<%endif%>

Can you see any way of doing this?
Quote Reply
Re: [joeybone] if clause In reply to
Easy - just do:

Code:
<%split_up_value($Field)%>
<%loop value_split%>
<%if loop_value eq "option1"%>
<%LWP::Simple::get('http://domain.com/option1.html')%>
<%elsif loop_value eq "option2"%>
<%LWP::Simple::get('http://domain.com/option2.html')%>
<%endif%>
<%endloop%>

..etc

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] if clause In reply to
Thanks Andy. Works great.