Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

Numerical Operations on Variables

Quote Reply
Numerical Operations on Variables
When I try to do this
<%set foo = '11' /2 3%>
like in the documentation, and then a <%foo%>, instead of getting an expected 3.67, I got instead
11' /2 3

Can anyone tell me what I should do? Thanks

Quote Reply
Re: [dauhee] Numerical Operations on Variables In reply to
In Reply To:
When I try to do this
<%set foo = '11' /2 3%>
like in the documentation, and then a <%foo%>, instead of getting an expected 3.67, I got instead
11' /2 3

Can anyone tell me what I should do? Thanks

Whoops, that's a bug in the documentation. We had it in for a while to try it, but it was breaking normal set operations, so we had to take it out.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [jagerman] Numerical Operations on Variables In reply to
Then how do I assign a value to a variable?
Example Perl code :
$i = $j + 2;

How do I express the above in GT:Template?
Thanks.

Quote Reply
Re: [dauhee] Numerical Operations on Variables In reply to
Code:
<%set i = $j + 2 %>
should work.


Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Numerical Operations on Variables In reply to
Hi yogi

No it doesn't. It gives me a blank variable for i.

Any other suggestions?

Thanks.

Regards.

Quote Reply
Re: [dauhee] Numerical Operations on Variables In reply to
GT::Template does not support that.

Perhaps instead you should look at creating a global variable to do it for you.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [dauhee] Numerical Operations on Variables In reply to
Goto template->globals and add:

i => sub {
my $tags = shift;
return $tags->{j} + 2;
}

and then put <%i%>. That will run the function and return the output (j + 2).

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Numerical Operations on Variables In reply to
Hi Alex.

Thanks. That is what I am doing now to overcome the problem but I was hoping the GT::Template can handle it by itself.

Thanks again.

p.s. Just a suggestion only. maybe GT could consider using the template toolkit instead of your own GT::Template. Smile

Quote Reply
Re: [dauhee] Numerical Operations on Variables In reply to
Hi,

We may put it back in in a future version.

As for Template::Toolkit, the main reasons are:

1. It does not come installed with perl
2. It is non trivial to install manually
3. Is is difficult to bundle with (lots of dependancies)
4. It would not have the same syntax as the rest of our code (i.e. inherits from GT::Base same style, error handling, etc)

And if you don't have a c compiler, it's much quicker. =)

Cheers,

Alex
--
Gossamer Threads Inc.