create new tag
, view all tags

Back to Plugin Home

Variables Macro Language


Sometimes you needed to use icons, pictures as markers. Or you want to define header of your company or title of your work. You may type and retype and retype it in each TWiki page, or define in WebPreferences variables. I guess that this way is difficult - i want to use small variables set on each document. Somethink like include directive of H file in C++ language. In this H file i'll define common variable and macroses and use it in my sources. I try to implement this in my plugin.

Syntax of declaration

Using of variable must be with it's variable declaration, as you can see in all languages smile . So look at example to understand how define a variable:

%VAR:DEF{"MyFirstVariable"}% Hello word %VAR:END%

This syntax grabbed from TWiki templates syntax. You can use %VAR:DEF {"name_of_variable"}% as begin at value of your variable, and you must end it by %VAR:END% token.

Syntax of printing variable value

As i say above the syntax is identical to TWiki templates syntax:


This print a value defined in variable "MyFirstVariable".


You can create a template with variables declarations for your purposes and include into other topic. Then you make include variables are come to defined state in total topic text and parsed correctly.



In this example in topic MyWeb.MyVariables there is a variable declaration:

%VAR:DEF{"TheTitleOfMyWork"}%---++ My first great work! :) %VAR:END%

And in each topic there is a include and use of this variable will be this title.

To define Global Variable, please define variables in this PhantomPluginVariables topic. Variable defined in this topic accessable from all TWiki pages with out additional includes.

How it work

The plugin collect all variables declarations at all topic text (this mean that you can use VAR:P before VAR:DEF smile , it's no matter) and map it to variables table. Then plugin remove all variables declarations from result text (you can't see at HTML your declarations) and replace VAR:P to value of corresponding variable. If varaible not found in declaration and DEBUG flag is 1 in PhantomPlugin, you can see error message in data/debug.txt log file.

How to debug

Sometimes variable not work. This mean that you not define it. You can set DEBUG flag in PhantomPlugin to 1 and see to data/debug.txt log for errors. List of all variables in topic you can also see in this log file.

-- AlexeyEfimov - 17 Nov 2002

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2002-11-20 - AlexeyEfimov
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.