r3 - 21 Feb 2005 - 05:41:06 - DavidBrightYou are here: TWiki >  Support Web > NestedVariableExpansion
Tags:
, create new tag

Question

This may be a general question of nested variable expansion, but I haven't found an answer yet (although there are topics which discuss related issues with CALC and SEARCH). I would like to use the SpreadSheetPlugin? to calculate new values for form elements. In order to do this, I need to retrieve the current value, which can be done with URLPARAM. Unfortunately, I cannot seem to find a way to embed the URLPARAM expansion into a CALC. For example, suppose I want a button on a calendar page that will go to the month previous to that shown. What I want is a formula like this:

%CALC{"$IF(%URLPARAM{"month"}% == 1,12,$EVAL(%URLPARAM{"month"}%-1))"}%
So that I end up with, if month currently equals 2:
%CALC{"$IF(2 == 1,12,$EVAL(2-1))"}%
Yielding a result of 1.

However, what I get is: ERROR: syntax error, near "=="

I'm confident TWiki has a way to accomplish this. Can someone enlighten me?

-- DavidBright - 18 Feb 2005

Environment

TWiki version: TWikiRelease02Sep2004
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin, SpreadSheetPlugin, CalendarPlugin
Server OS: Fedora Core 3
Web server: Apache 2.0.52
Perl version: 5.8.5
Client OS: WinXP?
Web Browser: FireFox? 1.0
Categories: Plugins
-- DavidBright - 18 Feb 2005

Answer

Not an answer, just an idea, but does the situation improve if you use a Set to assign the value of the URLPARAM to a local variable before the line containing your CALC?

I suspect this is a problem with the tag parser, and by "easing the load" it may suddenly work.

-- CrawfordCurrie - 20 Feb 2005

Thanks for the pointer, Crawford. At first it didn't work, but I spent more time on it and realized that the URLPARAM was blank on the first call, so the == test was trying to compare blank with a number. That was the error. In the end, though, I ended up using some separate $SETs and calculations just to make it easier to follow. Here is what I ended up with:

%CALC{"$SET(month, %URLPARAM{"month"}%)"}%
%CALC{"$IF($EXACT($GET(month),), $SET(month, $FORMATTIME($TODAY(), $month)),)"}%
%CALC{"$IF($GET(month) == 1, $SET(pmonth, 12),$SET(pmonth, $EVAL($GET(month)-1)))"}%

There are similar calculations for the year, of course, but this should give you the idea.

We can mark this one answered. Thanks again!

-- DavidBright - 21 Feb 2005

 
Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r3 < r2 < r1 | More topic actions
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback SourceForge.net Logo