%META:TOPICINFO{author="mikee" date="1029748440" format="1.0" version="1.0"}%
---++ %TOPIC%

Sometimes you want to have the same word, color, or text in many places.
Instead of manually editing the topic page define a variable at the top that
is used everywhere in the topic. You can change the value of a variable
several times in a single topic. All references to a variable will use the
most recent definition. The empty set ('') may be used to define nothing.

This <nop>PlugIn defines four 'functions'. You may either set a variable to a
value, request the value of a variable, delete a variable, or list all
variables. It is valid to request the value for a variable that is not yet
set. The value 'undefined' is returned in this case. The list of defined
variables returned by %<nop>VARIABLELIST% uses the TablePlugin syntax.

---+++ Syntax Rules

Use the ={key,value}= form to define a variable and use the ={key}= form to
get the current value of =key=.

<blockquote style="background-color:#f5f5f5">
   * =%<nop>VARIABLE{key,value}%=
   * =%<nop>VARIABLE{key}%=
   * =%<nop>VARIABLEDELETE{key}%=
   * =%<nop>VARIABLELIST{key}%=
</blockquote>

---+++ Examples

   * %VARIABLEDEFINE{company, 'Widgets, Inc.'}%
   * %VARIABLERETURN{company}%
      => 'Widgets, Inc.'
   * %VARIABLERETURN{othercompany}% (not yet defined)
      => 'undefined'
   * %VARIABLEDELETE{company}%
      => nothing
   * %VARIABLELIST{company}%
      =>

         | *Key* | *Value* |
         | var1  | val2    |
         | var2  | val2    |
         ...
         | varN  | valN    |

Define three values and cause the background of text to be the defined color.

<verbatim>
 %VARIABLEDEFINE{owned,#BBFFBB}%
 %VARIABLEDEFINE{leased,#FFCCFF}%
 %VARIABLEDEFINE{retired,#EEEEEE}%
 %VARIABLELIST%
 <style background-color:%VARIABLERETURN{owned}%>owned=%VARIABLERETURN{owned}%</style>
 <font color=%VARIABLERETURN{leased}%>leased=%VARIABLERETURN{leased}%</font>
 <font color=%VARIABLERETURN{retired}%>retired=%VARIABLERETURN{retired}%</font>
</verbatim>

%VARIABLEDEFINE{owned,#BBFFBB}%
%VARIABLEDEFINE{leased,#FFCCFF}%
%VARIABLEDEFINE{retired,#EEEEEE}%
%VARIABLELIST%

<font color="%VARIABLERETURN{owned}%">owned=%VARIABLERETURN{owned}%</font><br>
<font color="%VARIABLERETURN{leased}%">leased=%VARIABLERETURN{leased}%</font><br>
<font color="%VARIABLERETURN{retired}%">retired=%VARIABLERETURN{retired}%</font><br>

Define a table using a background color that comes from a variable.

%TABLE{ tableframe="box" sort="off" tableborder="1" %databg="#00CCFF,%VARIABLERETURN{owned}%,%VARIABLERETURN{leased}%,%VARIABLERETURN{retired}%" }%

| Colors |
| Owned |
| Loaned/Leased |
| Retired |


#TopicHANK

<verbatim>
%TABLE{ tableframe="box" sort="off" tablewidth="100%" columnwidths="20%,80%" databg="%VARIABLERETURN{owned}%" cellpadding="2" tableborder="1" }%
</verbatim>

%TABLE{ tableframe="box" sort="off" tablewidth="100%" columnwidths="20%,80%" databg="%VARIABLERETURN{owned}%" cellpadding="2" tableborder="1" }%

| hostname | hank                          |
| make     | [[http://www.dell.com][Dell]] |

---+++ <nop>%TOPIC% settings

<blockquote style="background-color:#f5f5f5">
   * Set DEBUG = 0
</blockquote>

---+++ Plugin Installation Instructions

Extract <nop>VariablesPlugin.zip, edit the <nop>VariablesPlugin-topic to
your needs and have fun.  There is an install script at the top of
the unpacked director that might help with installing this plugin.
Also, enable the plugin using the configure script in twiki.
Execute this script by:

   * # unzip -v VariablesPlugin.zip
   * # cd twikiVariables
   * # ./install.sh /var/www/html/twiki
      * change the above path to where your twiki is installed

---+++ Files

	* ==lib/TWiki/Plugins/VariablesPlugin.pm==
	* ==data/TWiki/VariablesPlugin.txt==

---+++ Plugin Info

|  Plugin Author: | %MAINWEB%.MikeEggleston |
|  Plugin Version: | 1.0 |
|  Change History: | 20 Nov 06: Initial Version |
|  CPAN Dependencies: | none |
|  Other Dependencies: | none |
|  Perl Version: | 5.0 |
|  Plugin Home: | http://TWiki.org/cgi-bin/view/Plugins/%TOPIC% |
|  Feedback: | http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%Dev |

---+++ History

   * 1.0: first version

---+++ Contributors

__Related Topics:__ %TWIKIWEB%.TWikiPreferences, %TWIKIWEB%.TWikiPlugins
