%META:TOPICINFO{author="ProjectContributor" date="1231502400" format="1.1" version="1"}%
%META:TOPICPARENT{name="WebHome"}%
%STARTSECTION{type="include"}%
---+ Macros

_Special text strings expand on the fly to display user data or system info_

Macros are text strings - =%<nop>MACRONAME%= or =%<nop>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
   1 Predefined macros: Defined by the system or by Plugins (for example, the SpreadSheetPlugin introduces a =%<nop>CALC{}%= macro)

%TOC%

---++ Using Macros

To use a macro type its name. For example,
   * type =%<nop>T%= to get %T% (a [[%SYSTEMWEB%.PreferenceSettings][preference settings]])
   * type =%<nop>TOPIC%= to get =%TOPIC%= (a predefined [[macro]])
   * type =%<nop>CALC{ "$UPPER(Text)" }%= to get =TEXT= (a [[macro]] defined by a Plugin)

*Note:*
   * To leave a macro unexpanded, precede it with an exclamation point, e.g. type =!%<nop>TOPIC%= to get =%<nop>TOPIC%=
   * Macros are expanded relative to the topic they are _used_ in, not the topic they are _defined_ in
   * Type =%<nop>ALLVARIABLES%= to get a full listing of all macros defined for a particular topic

---++ 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. =%<nop>MYVAR%=, =%<nop>MyVar%=, =%<nop>My2ndVar%=, and =%<nop>My_Var%= are all valid macro names. Macros are case sensitive. =%<nop>MyVAR%= and =%<nop>MYVAR%= are not the same macro.

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

#SettingPrefs
#PreferencesMacros
---++ 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 [[%SYSTEMWEB%.DefaultPreferences][%SYSTEMWEB%.DefaultPreferences]] (*not* recommended)
   1 plugin topics (see [[Plugins]])
   1 local site level in [[%LOCALSITEPREFS%][%LOCALSITEPREFS%]]
   1 user level in individual user topics in %USERSWEB% web
   1 web level in %WEBPREFSTOPIC% of a parent web
   1 web level in %WEBPREFSTOPIC% of the web
   1 topic level in topics in webs
   1 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 [[%SYSTEMWEB%.PreferenceSettings][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: <br /> =[multiple of 3 spaces] * [space] Set [space] MACRONAME [space] = [space] value=
<blockquote>
*Examples:*
   * ==<nop>Set MACRONAME = value==
      * ==<nop>Set MACRONAME = value==
</blockquote>
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.
<blockquote>
*Example:*
<pre>
   * <nop>Set MACRONAME = value starts here
     and continues here
</pre>
</blockquote>

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

<blockquote>
*Example: Create a custom logo macro* <br />
   * To place a logo anywhere in a web by typing ==%<nop>MYLOGO%==, define the [[%SYSTEMWEB%.PreferenceSettings][preference settings]] on the web's WebPreferences topic, and upload a logo file, ex: =mylogo.gif=. You can upload by [[FileAttachment][attaching the file]] to WebPreferences, or, to avoid clutter, to any other topic in the same web, e.g. =LogoTopic=. Sample preference setting in WebPreferences:
      * ==<nop>Set MYLOGO = %<nop>PUBURL%/%<nop>WEB%/LogoTopic/mylogo.gif==
</blockquote>

You can also set [[%SYSTEMWEB%.PreferenceSettings][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:
<verbatim>
   * Set EDITBOXHEIGHT = 10
   * Local EDITBOXHEIGHT = 20
</verbatim>
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! =%<nop>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.

#PreDef
---++ 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 =%<nop>SEARCH%=, are powerful and general tools.

   * %X% Predefined macros can be overridden by [[%SYSTEMWEB%.PreferenceSettings][preference settings]] (except TOPIC and WEB)
   * %X% Plugins may extend the set of predefined macros (see individual Plugins topics for details)
   * %T% *Take the time to thoroughly read through ALL preference macros.* If you actively configure your site, review macros periodically. They cover a wide range of functions, and it can be easy to miss the one perfect macro for something you have in mind. For example, see =%<nop>BASETOPIC%=, =%<nop>INCLUDE%=, and the mighty =%<nop>SEARCH%=.

This version of Foswiki - %WIKIVERSION% - predefines the following macros:

%SEARCH{
    "^Var[A-Z_0-9]+$"
    casesensitive="on"
    web="%SYSTEMWEB%"
    type="regex"
    scope="topic"
    format="$percntINCLUDE{$web.$topic}$percnt"
    nonoise="on"
}%

---+++ Shortcuts

The following macros are [[%SYSTEMWEB%.PreferenceSettings][preference settings]] and are frequently used in topic content.
   * =%<nop>BR%= - line break
   * =%<nop>BULLET%= - bullet sign
   * =%<nop>BB%= - line break and bullet combined
   * =%<nop>BB2%= - indented line break and bullet
   * =%<nop>RED% text %<nop>ENDCOLOR%= - colored text (also =%<nop>YELLOW%=, =%<nop>ORANGE%=, =%<nop>PINK%=, =%<nop>PURPLE%=, =%<nop>TEAL%=, =%<nop>NAVY%=, =%<nop>BLUE%=, =%<nop>AQUA%=, =%<nop>LIME%=, =%<nop>GREEN%=, =%<nop>OLIVE%=, =%<nop>MAROON%=, =%<nop>BROWN%=, =%<nop>BLACK%=, =%<nop>GRAY%=, =%<nop>SILVER%=, =%<nop>WHITE%=)
   * =%<nop>H%= - %H% Help icon
   * =%<nop>I%= - %I% Idea icon
   * =%<nop>M%= - %M% Moved to icon
   * =%<nop>N%= - %N% New icon
   * =%<nop>P%= - %P% Refactor icon
   * =%<nop>Q%= - %Q% Question icon
   * =%<nop>S%= - %S% Pick icon
   * =%<nop>T%= - %T% Tip icon
   * =%<nop>U%= - %U% Updated icon
   * =%<nop>X%= - %X% Alert icon
   * =%<nop>Y%= - %Y% Done icon

See ShortcutMacros for a full list of predefined shortcuts.

%ENDSECTION{type="include"}%

---
*Related Topics:* UserDocumentationCategory

