Gossamer Forum
Home : Products : Gossamer Links : Discussions :

If.. then on a template page

Quote Reply
If.. then on a template page
I am trying to add some extra functionality to a page... it is just an esoteric change, but it would be cool. I have a field for "Years"... it can be "2004" or "2004-" i want XXXX, but if it is "1999-2004" I want YYYYY.

So I am thinking if there is a count, I can do if count.years=9 then YYYY else XXXX.... is there a way to do this?

Thanks and happy new year!!
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] If.. then on a template page In reply to
Hi Dave,

In templates you can do:

Code:
<%if length($Years) == 9%>YYYY<%else%>XXXX<%endif%>

Hope this helps Smile

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins

Last edited by:

eupos: Jan 11, 2013, 7:28 PM
Quote Reply
Re: [eupos] If.. then on a template page In reply to
Boris:

That is PERFECT- exactly what I need. Templates are so powerful, I figured there would be a way.... I just did not know how. Thanks- you just made my site a littler better!
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] If.. then on a template page In reply to
Cool Smile

Glad I helped Wink

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] If.. then on a template page In reply to
Whoops! Did not work. I checked my variable name, and it was correct, so I ran this:

<%meta_name%> <%if length($Years) > 3%>was<%else%>is <%length($Years)%><%endif%> based in <%Country%>.

And I got this:

Error: Variable 'length' is not a code reference...

So maybe it is a different command?
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] If.. then on a template page In reply to
Mmmm which GLinks version is that?

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] If.. then on a template page In reply to
3.1.0
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] If.. then on a template page In reply to
Mmm not sure it's in 3.1.0. I tested it with 3.3.0

Do you have a reason not to upgrade?

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [carfac] If.. then on a template page In reply to
Hi,

Can you try:

Code:
<%set testlength = length($Years) %>
FOO: <%testlength%>

I believe the problem you're having is due to the fact the conditions are not actually processed with the logic you are expecting. This logic I believe was changed in 3.2+, as I'm pretty sure that code Boris gave works fine in 3.2+

If that works, you would just have to use something like:

Code:
<%set testlength = length($Years) %>
<%if testlength > 3%>test<%elsif testlength== 4%>something else<%endif%>

Hope that helps

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: [eupos] If.. then on a template page In reply to
I am so cumtomized on my current install, I hate to chance an upgrade. I have modified a LOT of core files... mainly just in the user subdirecory I guess. Maybe I will try a dev upgrade and see how that runs.
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] If.. then on a template page In reply to
Andy... ran that code and got a blank field, so id does not work well in 3.1.0...

OK, I will start backing up, and build a dev version and see how hard an upgrade is for me!
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] If.. then on a template page In reply to
Put this in globals then:

Code:
sub {
my $string = shift;
return length($string);
}

name it length and keep rolling Wink

Use the code I gave you and you'll be fine.

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] If.. then on a template page In reply to
Dang- that was easy! And yes, it DOES work....

I am still looking at upgrading to 3.3... I have it d/led already, and I am settin up a test server. Maybe I can clean stuff up at the same time!

Again, thanks!
dave

Big Cartoon DataBase
Big Comic Book DataBase
Quote Reply
Re: [carfac] If.. then on a template page In reply to
Cool Wink

And yeah, do that.

3.3.0 is worth it.

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins