Using SpreadSheetPlugin variables for more flexible preferences

  • Tip Category - Developing Wiki Applications
  • Tip Added By - GeorgeClark - 10 Dec 2013 - 16:16
  • Extensions Used - SpreadSheetPlugin
  • Useful To - Intermediate
  • Tip Status - New
  • Related Topics -

Problem

In Foswiki 1.0.x and Foswiki 1.1.x, it's not possible to set a preference in an included section or topic.

Context

Sometimes it would be very helpful to centralized all preference settings into a single common topic for a group of topics.

Solution

The solution in Foswiki 1.0.x, 1.1.x (and also TWiki) is to use SpreadsheetPlugin variables instead of Preference settings. (Foswiki 1.2 will include a == macro which can be used to set preferences in an include.

Known Uses

In this example, a group of topics were used by students in a lab setting. Each "Lab" could be tailored for one of the "stations". A station had a team name, and a fixed group of IP addresses, host names, etc. Rather than code each of these into every topic, a single "LabSettings" topic was established which would be %INCLUDEd into the the topic.

The "Setting" topic - StationSetup

This topic is designed to be "included" into other lab topics.  Sections include:

   * section =selectstation=  Inserts the form used to select the station *Include at very top to be obvious*
   * section =sets=   *Include next - sets reference variables for addresses*.
   * section =hub=  Formats hub addressing for inclusion into a lab

---++ Following variables are set on this page
%STARTSECTION{"display"}%
| =%CALC{$GET(ep1)}%= | Endpoint 1 Address |
| =%CALC{$GET(ep1net)}%= | Endpoint 1 Network |
| =%CALC{$GET(enetr1)}%= | Router 1 Address |
| =%CALC{$GET(ep2)}%= | Endpoint 2 Address |
| =%CALC{$GET(ep2net)}%= | Endpoint 2 Network |
| =%CALC{$GET(station1)}%= | Station 1 Name |
| =%CALC{$GET(station2)}%= | Station 2 Name |
%ENDSECTION{"display"}%

%STARTSECTION{"selectstation"}%
*Note:* Enter your Station number (1-6) and press the [GO] button to display the actual addressing required to complete the lab for your Station:

<form name="interactive" action="%SCRIPTURL%/view%SCRIPTSUFFIX%/%INCLUDINGWEB%/%INCLUDINGTOPIC%" method="get">
<noautolink>
Station: <input type="text" name="team" size="10" value="%URLPARAM{ "team" default="1" encode="entity" }%" /> &nbsp; <input type="submit" value="Go" /><br />
</noautolink>
</form>
%ENDSECTION{"selectstation"}%

%STARTSECTION{"sets"}%
%CALC{$SET(ep1, 10.100.1.$SUM(20,%URLPARAM{ "team" default="1" }% ))}%
%CALC{$SET(ep1net, 10.100.1.0)}%
%CALC{$SET(enetr1, 10.100.1.1%URLPARAM{ "team" default="1" }%)}%

%CALC{$SET(ep2, 10.10%URLPARAM{ "team" default="1" }%.1.2 )}%
%CALC{$SET(ep2net, 10.10%URLPARAM{ "team" default="1" }%.1.0 )}%

%CALC{$SET(station1, $LISTITEM(%URLPARAM{ "team" default="1" }%, Red, Green, Blue, Yellow, Orange, Violet))}%
%CALC{$SET(station2, $LISTITEM(%URLPARAM{ "team" default="1" }%, Red2, Green2, Blue2, Yellow2, Orange2, Violet2))}%
%ENDSECTION{"sets"}%

%STARTSECTION{"hub"}%
---++++ "Hub" side Ethernet addressing

<blockquote>
%TABLE{sort="off"}%
| *Device*  | *IP Address* | *mask (CIDR length)* |
| router1 ethernet 0/1 | %CALC{$GET(enetr1)}% | 255.255.255.0 (24) |
| Endpoint 1 PC | %CALC{$GET(ep1)}% | 255.255.255.0 (24) |
</blockquote>
%ENDSECTION{"hub"}%


Using the include

%INCLUDE{"%TOPIC%" section="selectstation"}%
%INCLUDE{"%TOPIC%" section="sets"}%

%INCLUDE{"%TOPIC%" section="display"}%
%INCLUDE{"%TOPIC%" section="hub"}%

Note: Enter your Station number (1-6) and press the [GO] button to display the actual addressing required to complete the lab for your Station:

Station:  

10.100.1.21 Endpoint 1 Address
10.100.1.0 Endpoint 1 Network
10.100.1.11 Router 1 Address
10.101.1.2 Endpoint 2 Address
10.101.1.0 Endpoint 2 Network
Red Station 1 Name
Red2 Station 2 Name

"Hub" side Ethernet addressing

Device IP Address mask (CIDR length)
router1 ethernet 0/1 10.100.1.11 255.255.255.0 (24)
Endpoint 1 PC 10.100.1.21 255.255.255.0 (24)

Known Limitations

See Also

BestPracticeTipsForm edit

Category Developing Wiki Applications
Related Topics
Topic revision: r1 - 10 Dec 2013, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy