Daya Bay Reactor Neutrino Experiment TWiki > SetGetPlugin Daya Bay webs:
Public | 中文 | Internal | Help

Log In or Register


Set and get variables in topics, optionally persistently across topic views


Use %SET{}% to store arbitrary text in a named variable, and reuse it with %GET{}% later on within the topic or an included topics. By default, variables live only during topic rendering time, e.g. they do not persist between topic views. It is also possible to remember the variables between topic views, however they are not version controlled like other content in TWiki.

%SET{}% and %GET{}% can be nested inside other TWiki variables and get handled as expected, e.g. inside out, and left to right.

Alternatives to this plugin are:

Syntax Rules

SET{"name" value="..."} -- set a variable

ALERT! Important notes when using the remember option:

GET{"name"} -- get a variable

SETGETDUMP{...} -- dump persistent variables


Set several times

A variable can be set and used several times.

Raw text:

   * Set "demo" to "uno": %SET{ "demo" value="uno" }%
   * Get "demo": %GET{ "demo" }%
   * Set "demo" to "due": %SET{ "demo" value="due" }%
   * Get "demo": %GET{ "demo" }%
   * Set "demo" to "tre": %SET{ "demo" value="tre" }%
   * Get "demo": %GET{ "demo" }%

  Rendered text:

  • Set "demo" to "uno":
  • Get "demo": uno
  • Set "demo" to "due":
  • Get "demo": due
  • Set "demo" to "tre":
  • Get "demo": tre

Search and save result

A SEARCH result can be assigned to a variable for later use. This can be useful for performance reasons if you need the result multiple times. The result can also be post-processed, such as with a $LISTMAP() of the SpreadSheetPlugin.

Raw text:

  separator=", "
   * Result: %GET{result}%
   * Again: %GET{result}%

  Rendered text:

Last topic view

In a topic, set a variable with the remember flag set that stores the current time. Add also a GET before the SET, it will show the time the topic has last been viewed.

Raw text:

   * Last view: %GET{ "SetGetPlugin-lastview" }%
   * Now: %SET{ "SetGetPlugin-lastview" remember="1" 
      value="%SERVERTIME{$year-$mo-$day $hou:$min:$sec}%"
     %GET{ "SetGetPlugin-lastview" }%

  Rendered text:

  • Last view: 2019-03-19 00:28:52
  • Now: 2019-03-19 03:33:13

Remember my mood

This example shows how you can remember the mood of users. The form shows a picklist to select a mood. The mood is stored persistently per user, and shown.

Raw text:

 "defined 'mood'"
  \"SetGetPlugin-mood-%WIKINAME%\" remember=\"1\" 
My current mood:
  %GET{ "SetGetPlugin-mood-%WIKINAME%" }%

<form action="%SCRIPTURL{view}%/%WEB%/%TOPIC%#MyMood">
Change my mood: <select name="mood">
<option>:-D</option> <option>:-)</option>
<option>:-I</option> <option>:-(</option>
<input type="submit" value="Set" class="twikiSubmit" />

  Rendered text:

My current mood:   smile for TWikiGuest

Change my mood:

REST Interface

Variables can also be set and retrieved by invoking a REST (REpresentational State Transfer) request on the TWiki server using the rest script. To persistently remember the state of interactive browser-based JavaScript applications, you can set and get variables using this REST interface via Ajax calls.

The rest script requires authentication, e.g. the user agent is prompted to authenticate if needed.

rest/SetGetPlugin/set -- set a variable

To set a variable call %SCRIPTURL{rest}%/SetGetPlugin/set. It accepts the following URL parameters:


rest/SetGetPlugin/get -- get a variable

To get a variable call %SCRIPTURL{rest}%/SetGetPlugin/get. It accepts the following URL parameters:


Plugin Settings

Show details toggleopen.gif Hide details toggleclose.gif
Plugin settings are stored as preferences variables. To reference a plugin setting write %<plugin>_<setting>%, i.e. %NEWPLUGIN_SHORTDESCRIPTION%

Plugin Installation Instructions

This plugin is pre-installed. TWiki administrators can upgrade the plugin as needed on the TWiki server.

Show details toggleopen.gif Hide details toggleclose.gif

Plugin Info

Plugin Author: TWiki:Main.PeterThoeny
Copyright: © 2010-2013 TWiki:Main.PeterThoeny
© 2010-2013 TWiki:TWiki.TWikiContributor
License: GPL (GNU General Public Licen:se External link mark)
Plugin Version: 2013-01-28
Show Change History toggleopen.gif Hide Change History toggleclose.gif
2013-01-28: TWikibug:Item7091: Use TWISTY in installation instructions and change history
2012-11-12: TWikibug:Item7032: GET variable with format parameter
2012-11-12: TWikibug:Item7020: Categorize TWiki Variable SET, GET, SETGETDUMP
2012-10-11: TWikibug:Item6978: SetGetPlugin::Core::_savePersistentVar() may fail at Data::Dumper->Dump(). "require Data::Dumper;" line added before that. -- TWiki:Main.HideyoImazu
2012-09-25: TWikibug:Item6943: Add REST interface
2012-01-06: TWikibug:Item6828: Removing write to persistent if already exists, and adding data dump -- TWiki:Main.AaronLWalker
2011-07-09: TWikibug:Item6725: Change global package variables from "use vars" to "our"
2011-04-04: TWikibug:Item6638: Small doc improvements
2011-03-26: TWikibug:Item6670: Make variables persistent across topic invocations
2010-10-17: TWikibug:Item6597: Initial version
TWiki Dependency: $TWiki::Plugins::VERSION 1.1
CPAN Dependencies: none
Other Dependencies: none
Perl Version: 5.005
Benchmarks: GoodStyle 100%, FormattedSearch 99%, SetGetPlugin 99%
Plugin Home:

Related Topics: VarSET, VarGET, TWikiPlugins, DeveloperDocumentationCategory, AdminDocumentationCategory, TWikiPreferences, SpreadSheetPlugin

Revision: r5 - 2013-01-29 - 12:17:47 - TWikiContributor

Copyright © 1999-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Daya Bay? Send feedback
Note: Please contribute updates to this topic on at TWiki:TWiki.SetGetPlugin.