Macros

Special text strings expand on the fly to display user data or system info

Macros are text strings - %MACRONAME% or %MACRONAME{ parameter="value" }% - that expand into content whenever a topic is rendered for viewing. There are two types of macros:

  1. Preference settings: Can be defined and changed by the user
  2. Predefined macros: Defined by the system or by Plugins (for example, the SpreadSheetPlugin introduces a %CALC{}% macro)

On this page:

Using Macros

To use a macro type its name. For example,

Note:

Macro Names

Macro names must start with a letter. The following characters can be letters, numbers and the underscore '_'. You can use both upper-case and lower-case letters and you can mix the characters. E.g. %MYVAR%, %MyVar%, %My2ndVar%, and %My_Var% are all valid macro names. Macros are case sensitive. %MyVAR% and %MYVAR% are not the same macro.

By convention all settings, predefined macros and macros used by plugins are always UPPER-CASE.

Preferences

Preferences settings are simple macros that do not accept parameters, and are defined in topics. A lot of the macros you will encounter are of this type.

Preferences can be defined by the user in various places.

Setting Preferences

You can set macros in all the following places:
  1. default level in System.DefaultPreferences (not recommended)
  2. plugin topics (see Plugins)
  3. local site level in Main.SitePreferences
  4. user level in individual user topics in Main web
  5. web level in WebPreferences of a parent web
  6. web level in WebPreferences of the web
  7. topic level in topics in webs
  8. session macros (if sessions are enabled)

Settings at higher-numbered levels override settings of the same macro at lower numbered levels, unless the macro was included in the setting of FINALPREFERENCES at a lower-numbered level, in which case it is locked at the value it has at that level.

If you are setting a preference and using it in the same topic, note that Foswiki reads all the preference settings from the saved version of the topic before it displays anything. This means you can use a macro anywhere in the topic, even if you set it somewhere inconspicuous near the end. But beware: it also means that if you change the setting of a macro you are using in the same topic, Preview will show the wrong thing, and you must Save the topic to see it correctly.

The syntax for setting macros is the same anywhere:
[multiple of 3 spaces] * [space] Set [space] MACRONAME [space] = [space] value

Examples:
  • Set MACRONAME = value
    • Set MACRONAME = value
Spaces between the = sign and the value will be ignored. You can split a value over several lines by indenting following lines with spaces - as long as you don't try to use * as the first character on the following line.
Example:
   * Set MACRONAME = value starts here
     and continues here

Whatever you include in your Macro will be expanded on display, exactly as if it had been entered directly.

Example: Create a custom logo macro

You can also set preference settings in a topic by clicking the link Edit topic preference settings under More topic actions. Preferences set in this manner are not visible in the topic text, but take effect nevertheless.

Access Control Settings

These are special types of preference settings to control access to content. AccessControl explains these security settings in detail.

Local values for preferences

Certain topics (a users home topic, web site and default preferences topics) have a problem; macros defined in those topics can have two meanings. For example, consider a user topic. A user may want to use a double-height edit box when they are editing their home topic - but only when editing their home topic. The rest of the time, they want to have a normal edit box. This separation is achieved using Local in place of Set in the macro definition. For example, if the user sets the following in their home topic:
   * Set EDITBOXHEIGHT = 10
   * Local EDITBOXHEIGHT = 20
Then when they are editing any other topic, they will get a 10 high edit box. However when they are editing their home topic, they will get a 20 high edit box. Local can be used wherever a preference needs to take a different value depending on where the current operation is being performed.

Use this powerful feature with great care! %ALLVARIABLES% can be used to get a listing of the values of all macros in their evaluation order, so you can see macro scope if you get confused.

Predefined Macros

Most predefined macros return values that were either set in the configuration when Foswiki was installed, or taken from server info (such as current username, or date and time). Some, like %SEARCH%, are powerful and general tools.

This version of Foswiki - Foswiki-1.0.9, Sun, 17 Jan 2010, build 6075 - predefines the following macros:

ACTIVATEDPLUGINS -- list of currently activated plugins

ADDTOHEAD

You can write %ADDTOHEAD{...}% in a topic or template. This variable accepts the following parameters: %ADDTOHEAD% expands in-place to the empty string, unless there is an error in which case the variable expands to an error string.

Use %RENDERHEAD% to generate the sorted head tags.

ADDTOZONE

%ADDTOZONE{
  "zone"
  ...
}%

Note, that using topic and section is actually a short form of

%ADDTOZONE{
   "myzone"
   text="$percntINCLUDE{\"topic\" section=\"section\" warn=\"off\"}$percnt"
}%

See also VarRENDERZONE

ALLVARIABLES -- list of currently defined macros

AQUA -- start aqua colored text

ATTACHURL -- full URL for attachments in the current topic

ATTACHURLPATH -- path of the attachment URL of the current topic

AUTHREALM -- authentication realm

BASETOPIC -- base topic where an INCLUDE started

BASEWEB -- base web where an INCLUDE started

BB -- bullet with line break

BB2 -- level 2 bullet with line break

BB3 -- level 3 bullet with line break

BB4 -- level 4 bullet with line break

BLACK -- start black colored text

BLUE -- start blue colored text

BR -- line break

BROWN -- start brown colored text

BULLET -- bullet character

CALC{"formula"} -- add spreadsheet calculations to tables and outside tables

CARET -- caret symbol

COMMENT{ attributes } -- insert an edit box into the topic to easily add comments.

DATE -- signature format date

DISPLAYTIME{"format"} -- formatted display time

EDITACTION -- Selects an edit template

EDITTABLE{ attributes } -- edit tables using edit fields and other input fields

ENCODE{"string"} -- encodes a string to HTML entities

ENDCOLOR -- end colored text

ENDSECTION{"name"} -- marks the end of a named section within a topic

ENV{"varname"} -- inspect the value of an environment variable

FAILEDPLUGINS -- debugging for plugins that failed to load, and handler list

FORMFIELD{"fieldname"} -- renders a field in the form attached to some topic

GMTIME{"format"} -- formatted GM time

GRAY -- start gray colored text

GREEN -- start green colored text

GROUPS -- a formatted list of groups

H -- help icon

HOMETOPIC -- home topic in each web

HTTP -- get HTTP headers

HTTP_HOST -- environment variable

HTTPS -- get HTTPS headers

I -- idea icon

ICON{"name"} -- small documentation graphic or icon of common attachment types

ICONURL{"name"} -- URL of small documentation graphic or icon

ICONURLPATH{"name"} -- URL path of small documentation graphic or icon

IF{"condition" ...} -- simple conditionals

INCLUDE{"page"} -- include other topic or web page

INCLUDINGTOPIC -- name of topic that includes current topic

INCLUDINGWEB -- web that includes current topic

LANGUAGE -- current user's language

LANGUAGES -- list available languages

LIME -- start lime colored text

LOCALSITEPREFS -- web.topicname of site preferences topic

LOGIN -- present a full login link

LOGOUT -- present a full logout link

M -- moved to... icon

MAINWEB -- synonym for USERSWEB

MAKETEXT -- creates text using Foswiki's I18N infrastructure

MAROON -- start maroon colored text

META -- displays meta-data

METASEARCH -- special search of meta data

N -- "new" icon

NAVY -- start navy blue colored text

NOP -- template text not to be expanded in instantiated topics

NOTIFYTOPIC -- name of the notify topic

OLIVE -- start olive green colored text

ORANGE -- start orange colored text

P -- pencil icon

PINK -- start pink colored text

PLUGINDESCRIPTIONS -- list of plugin descriptions

PLUGINVERSION -- the version of a Foswiki Plugin, or the Foswiki Plugins API

PUBURL -- the base URL of attachments

PUBURLPATH -- the base URL path of attachments

PURPLE -- start purple colored text

Q -- question icon

QUERYPARAMS -- show paramaters to the query

QUERYSTRING -- full, unprocessed string of parameters to this URL

RED -- start red colored text

! * Related: ENDCOLOR, DefaultPreferences, StandardColors

REMOTE_ADDR -- environment variable

REMOTE_PORT -- environment variable

REMOTE_USER -- environment variable

RENDERLIST -- render bullet lists in a variety of formats

RENDERZONE

%RENDERZONE{"zone" ...}%

Note, that you can create as many zones as you like. The plugin does not restrict you to use it only for body and head. Interesting use cases in wiki applications:

See also VarADDTOZONE

REVINFO -- revision information of current topic

REVINFO{"format"} -- formatted revision information of topic

S -- red star icon

SCRIPTNAME -- name of current script

SCRIPTSUFFIX -- script suffix

SCRIPTURL{"script"} -- URL of script

SCRIPTURLPATH{"script"} -- URL path of script

SEARCH{"text"} -- search content

SERVERTIME{"format"} -- formatted server time

SESSIONID -- unique ID for this session

SESSIONVAR -- name of CGI and session variable that stores the session ID

SESSION_VARIABLE -- get, set or clear a session variable

SILVER -- start silver colored text

SLIDESHOWEND -- end slideshow

SLIDESHOWSTART -- convert a topic with headings into a slideshow

SPACEDTOPIC -- topic name, spaced and URL-encoded deprecated

SPACEOUT{"string"} -- renders string with spaces inserted in sensible places

STARTINCLUDE -- start position of topic text if included

STARTSECTION -- marks the start of a section within a topic

STATISTICSTOPIC -- name of statistics topic

STOPINCLUDE -- end position of topic text if included

SUBSCRIBE{ attributes } - subscribe the current user for notification of changes to the current topic

Anywhere in a topic or template:

Parameter Default Meaning
who Logged-in user Who to subscribe (wikiname, no web)
topic Current topic Topic to subscribe to. Wildcards may be used e.g. topic="Item*" will subscribe to all topics starting with Item. Use topic="Main.*" to subscribe to the WebNotify for that web.
unsubscribe Not set If set to "on", will unsubscribe the user
format Simple HTML Link with an action anchor "Subscribe" or "Unsubscribe" Defines custom look-and-feel for subscribe link using the following format variables: $topics, $url, $wikiname, $action
formatunsubscribe format Serves same function as format, but allows the user to define a different format than subscribe.

SYSTEMWEB -- name of documentation web

T -- tip icon

TABLE{ attributes } -- control attributes of tables and sorting of table columns

TEAL -- start teal colored text

TOC{"Topic"} -- table of contents

TOPIC -- name of current topic

TOPICLIST{"format"} -- topic index of a web

TOPICURL -- shortcut to viewing the current topic

TWIKIWEB -- synonym for SYSTEMWEB

U -- "updated" icon

URLPARAM{"name"} -- get value of a URL parameter

USERINFO{"name"} -- retrieve details about a user

USERNAME -- your login username

USERSWEB -- name of users web

VAR{"NAME" web="Web"} -- get a preference value from another web

VBAR -- vertical bar

VOTE{ attributes } -- define a poll in a topic.

WEB -- name of current web

WEBLIST{"format"} -- index of all webs

WEBPREFSTOPIC -- name of web preferences topic

WHITE -- start white colored text

WIKIHOMEURL -- site home URL

WIKINAME -- your Wiki username

WIKIPREFSTOPIC -- name of site-wide preferences topic

WIKITOOLNAME -- name of your site

WIKIUSERNAME -- your Wiki username with web prefix

WIKIUSERSTOPIC -- name of topic listing all registers users

WIKIVERSION -- the version of the installed Foswiki engine

X -- warning icon

Y -- "yes" icon

YELLOW -- start yellow colored text

Shortcuts

The following macros are preference settings and are frequently used in topic content.

See ShortcutMacros for a full list of predefined shortcuts.


Related Topics: UserDocumentationCategory spacer