Macros

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

Macros are text strings in one of two forms:

%MACRONAME%
%MACRONAME{ parameter="value" }%

These usually expand into content when a topic is rendered for viewing. There are two types of macros:
  1. Preference settings: May be defined and modified by the user
  2. Registered macros: Defined by the system or by Plugins (for example, the SpreadSheetPlugin introduces a %CALC{}% macro)

Using Macros

To use a macro type its name. For example,

Note:
  • To leave a macro unexpanded, precede it with an exclamation point, e.g. type !%TOPIC% to get %TOPIC%
    • Alternatively, insert a <nop> anywhere in the macro, Eg. %<nop>TOPIC%
  • Macros are expanded relative to the topic they are used in, not the topic they are defined in
  • Type %ALLVARIABLES% to get a full listing of all macros defined for a particular topic
  • If a macro is not defined, then it will be left in the text unless it is called with a default parameter, in which case the value of the default parameter will replace the macro call in the output. For example, %UNDEFINED{default="blank"}% will expand to blank.

Order of expansion

The following describes only these types of macros:

Standard form

The key to understanding nested expressions in Foswiki is to understand that macros are expanded "inside-out, left-to-right". Example:

%MACRO1{
   something="%MACRO2{
      somethingelse="%MACRO3%, %MACRO4%"
   }%"
}%
The macros are expanded in this order: MACRO3, MACRO4, MACRO2, MACRO1.

Animated Example
%INCLUDE{
    "%QUERY{
        "'%THETOPIC%'/%THEFIELD%"
    }%"
    section="Summary"
}%
   * Set THETOPIC = %SYSTEMWEB%.FAQWhatIsWikiWiki
   * Set THEFIELD = TopicClassification
%INCLUDE{
    "%QUERY{
        "'%SYSTEMWEB%.FAQWhatIsWikiWiki'/%THEFIELD%"
    }%"
    section="Summary"
}%
   * Set THETOPIC = %SYSTEMWEB%.FAQWhatIsWikiWiki
   * Set THEFIELD = TopicClassification
%INCLUDE{
    "%QUERY{
        "'%SYSTEMWEB%.FAQWhatIsWikiWiki'/TopicClassification"
    }%"
    section="Summary"
}%
   * Set THETOPIC = %SYSTEMWEB%.FAQWhatIsWikiWiki
   * Set THEFIELD = TopicClassification
%INCLUDE{
    "%QUERY{
        "'System.FAQWhatIsWikiWiki'/TopicClassification"
    }%"
    section="Summary"
}%
   * Set THETOPIC = %SYSTEMWEB%.FAQWhatIsWikiWiki
   * Set THEFIELD = TopicClassification
%INCLUDE{
    "FrequentlyAskedQuestion"
    section="Summary"
}%
   * Set THETOPIC = %SYSTEMWEB%.FAQWhatIsWikiWiki
   * Set THEFIELD = TopicClassification

These topics are for frequently
asked questions including answers.

   * Set THETOPIC = %SYSTEMWEB%.FAQWhatIsWikiWiki
   * Set THEFIELD = TopicClassification

These topics are for frequently
asked questions including answers.

   * Set THETOPIC = System.FAQWhatIsWikiWiki
   * Set THEFIELD = TopicClassification

Delayed form

Standard form macros can nearly always be used to build the parameter string of another macro; however, sometimes it is desirable to bypass the inside-out expansion order and delay the inner macro until after the outer macro has finished expansion. This is accomplished by using the $percent format token instead of %, and escaping any " character it uses (becomes \")

TIP When working with a given macro, consult its documentation to determine which parameters support the $percent/$percnt format tokens. Generally only output parameters like header, format and footer support format tokens.
Example:
%MACRO1{
   format="$percentMACRO2{
      format=\"%MACRO3%, %MACRO4%\"
   }$percent"
}%
The macros are expanded in this order: MACRO3, MACRO4, MACRO1, MACRO2.
Animated Example
From the conditional output example:

%SEARCH{
  "info.date >= d2n('2009-01-01') AND info.date <= d2n('2009-12-31')"
  type="query"
  limit="2"
  nonoise="on"
  format="   * $percentICON{
    \"$percentIF{
      \"'$topic'/parent.name='%PARENT%'\"
      then=\"info\" else=\"gear\"
    }$percent\"
  }$percent [[$topic]]"
}%
----
   * Set PARENT = UserDocumentationCategory
%SEARCH{
  "info.date >= d2n('2009-01-01') AND info.date <= d2n('2009-12-31')"
  type="query"
  limit="2"
  nonoise="on"
  format="   * $percentICON{
    \"$percentIF{
      \"'$topic'/parent.name='UserDocumentationCategory'\"
      then=\"info\" else=\"gear\"
    }$percent\"
  }$percent [[$topic]]"
}%
----
   * Set PARENT = UserDocumentationCategory

         无法搜寻,错误: Error in tempfile() using /home/www/foswiki/working/tmp/XXXXXXXXXX: Could not create temp file /home/www/foswiki/working/tmp/h9eZvcA7Bv: No space left on device at /home/www/foswiki/lib/Foswiki/Sandbox.pm line 506
 at /usr/share/perl5/File/Temp.pm line 1381
	File::Temp::tempfile('File::Temp', 'STDERR.20722.XXXXXXXXXX', 'DIR', '/home/www/foswiki/working/tmp', 'UNLINK', 0) called at /home/www/foswiki/lib/Foswiki/Sandbox.pm line 506
	Foswiki::Sandbox::sysCommand('Foswiki::Sandbox', '/usr/bin/rlog  -r%REVISION|N% %FILENAME|F%', 'REVISION', 1.2, 'FILENAME', '/home/www/foswiki/data/System/AppendixEncodeURLsWithUTF8.txt,v') called at /home/www/foswiki/lib/Foswiki/Store/VC/RcsWrapHandler.pm line 323
	Foswiki::Store::VC::RcsWrapHandler::getInfo('Foswiki::Store::VC::RcsWrapHandler=HASH(0xa792db0)', undef) called at /home/www/foswiki/lib/Foswiki/Store/VC/Store.pm line 100
	Foswiki::Store::VC::Store::readTopic('Foswiki::Store::RcsWrap=HASH(0x8c582f0)', 'Foswiki::Meta=HASH(0xa796fa0)', undef) called at /home/www/foswiki/lib/Foswiki/Meta.pm line 968
	Foswiki::Meta::loadVersion('Foswiki::Meta=HASH(0xa796fa0)', undef) called at /home/www/foswiki/lib/Foswiki/Meta.pm line 430
	Foswiki::Meta::load('Foswiki::Meta', 'Foswiki=HASH(0x8c051d8)', 'System', 'AppendixEncodeURLsWithUTF8') called at /home/www/foswiki/lib/Foswiki/MetaCache.pm line 180
	Foswiki::MetaCache::get('Foswiki::MetaCache=HASH(0xa7857b0)', 'System', 'AppendixEncodeURLsWithUTF8') called at /home/www/foswiki/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm line 230
	Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery('Foswiki::Query::Node=HASH(0xa782920)', 'System', undef, 'Foswiki=HASH(0x8c051d8)', 'HASH(0xa7393a0)') called at /home/www/foswiki/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm line 78
	Foswiki::Store::QueryAlgorithms::BruteForce::query('Foswiki::Query::Node=HASH(0xa782920)', undef, 'Foswiki=HASH(0x8c051d8)', 'HASH(0xa7393a0)') called at /home/www/foswiki/lib/Foswiki/Store/VC/Store.pm line 518
	Foswiki::Store::VC::Store::query('Foswiki::Store::RcsWrap=HASH(0x8c582f0)', 'Foswiki::Query::Node=HASH(0xa782920)', undef, 'Foswiki=HASH(0x8c051d8)', 'HASH(0xa7393a0)') called at /home/www/foswiki/lib/Foswiki/Meta.pm line 839
	Foswiki::Meta::query('Foswiki::Query::Node=HASH(0xa782920)', undef, 'HASH(0xa7393a0)') called at /home/www/foswiki/lib/Foswiki/Search.pm line 352
	Foswiki::Search::searchWeb('Foswiki::Search=HASH(0x969ce08)', 'search', 'info.date >= d2n(\'2009-01-01\') AND info.date <= d2n(\'2009-...', 'basetopic', 'Macros', '_RAW', '\x{a}  "info.date >= d2n(\'2009-01-01\') AND info.date <= d2n(\'2...', 'nonoise', 'on', ...) called at /home/www/foswiki/lib/Foswiki/Macros/SEARCH.pm line 32
	Foswiki::__ANON__() called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 379
	eval {...} called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 371
	Error::subs::try('CODE(0xa6a0d28)', 'HASH(0xa723aa8)') called at /home/www/foswiki/lib/Foswiki/Macros/SEARCH.pm line 41
	Foswiki::SEARCH('Foswiki=HASH(0x8c051d8)', 'Foswiki::Attrs=HASH(0xa6a0c18)', 'Foswiki::Meta=HASH(0x968e440)') called at /home/www/foswiki/lib/Foswiki.pm line 3145
	Foswiki::_expandMacroOnTopicRendering('Foswiki=HASH(0x8c051d8)', 'SEARCH', '\x{a}  "info.date >= d2n(\'2009-01-01\') AND info.date <= d2n(\'2...', 'Foswiki::Meta=HASH(0x968e440)') called at /home/www/foswiki/lib/Foswiki.pm line 3021
	Foswiki::_processMacros('Foswiki=HASH(0x8c051d8)', '%STARTINCLUDE%\x{a}---+ Macros\x{a}\x{a}_Special text strings expand on t...', 'CODE(0x8bac9b8)', 'Foswiki::Meta=HASH(0x968e440)', 16) called at /home/www/foswiki/lib/Foswiki.pm line 2818
	Foswiki::innerExpandMacros('Foswiki=HASH(0x8c051d8)', 'SCALAR(0x8bad438)', 'Foswiki::Meta=HASH(0x968e440)') called at /home/www/foswiki/lib/Foswiki.pm line 3327
	Foswiki::expandMacros('Foswiki=HASH(0x8c051d8)', '%STARTINCLUDE%\x{a}---+ Macros\x{a}\x{a}_Special text strings expand on t...', 'Foswiki::Meta=HASH(0x968e440)') called at /home/www/foswiki/lib/Foswiki/Meta.pm line 3103
	Foswiki::Meta::expandMacros('Foswiki::Meta=HASH(0x968e440)', '%STARTINCLUDE%\x{a}---+ Macros\x{a}\x{a}_Special text strings expand on t...') called at /home/www/foswiki/lib/Foswiki/UI/View.pm line 412
	Foswiki::UI::View::_prepare('%STARTINCLUDE%\x{a}---+ Macros\x{a}\x{a}_Special text strings expand on t...', 'Foswiki::Meta=HASH(0x968e440)', 0) called at /home/www/foswiki/lib/Foswiki/UI/View.pm line 392
	Foswiki::UI::View::view('Foswiki=HASH(0x8c051d8)') called at /home/www/foswiki/lib/Foswiki/UI.pm line 316
	Foswiki::UI::__ANON__() called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 379
	eval {...} called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 371
	Error::subs::try('CODE(0x8637958)', 'HASH(0x8c04f18)') called at /home/www/foswiki/lib/Foswiki/UI.pm line 435
	Foswiki::UI::_execute('Foswiki::Request=HASH(0x8bf1580)', 'CODE(0x8bcd688)', 'view', 1) called at /home/www/foswiki/lib/Foswiki/UI.pm line 274
	Foswiki::UI::handleRequest('Foswiki::Request=HASH(0x8bf1580)') called at /home/www/foswiki/lib/Foswiki/Engine/CGI.pm line 41
	Foswiki::Engine::CGI::run('Foswiki::Engine::CGI=HASH(0x8853b48)') called


----
   * Set PARENT = UserDocumentationCategory

         无法搜寻,错误: Error in tempfile() using /home/www/foswiki/working/tmp/XXXXXXXXXX: Could not create temp file /home/www/foswiki/working/tmp/K0oRL5AFZ3: No space left on device at /home/www/foswiki/lib/Foswiki/Sandbox.pm line 506
 at /usr/share/perl5/File/Temp.pm line 1381
	File::Temp::tempfile('File::Temp', 'STDERR.20722.XXXXXXXXXX', 'DIR', '/home/www/foswiki/working/tmp', 'UNLINK', 0) called at /home/www/foswiki/lib/Foswiki/Sandbox.pm line 506
	Foswiki::Sandbox::sysCommand('Foswiki::Sandbox', '/usr/bin/rlog  -r%REVISION|N% %FILENAME|F%', 'REVISION', 1.2, 'FILENAME', '/home/www/foswiki/data/System/BulkResetPassword.txt,v') called at /home/www/foswiki/lib/Foswiki/Store/VC/RcsWrapHandler.pm line 323
	Foswiki::Store::VC::RcsWrapHandler::getInfo('Foswiki::Store::VC::RcsWrapHandler=HASH(0xa7b0620)', undef) called at /home/www/foswiki/lib/Foswiki/Store/VC/Store.pm line 100
	Foswiki::Store::VC::Store::readTopic('Foswiki::Store::RcsWrap=HASH(0x8c582f0)', 'Foswiki::Meta=HASH(0xa7b31f8)', undef) called at /home/www/foswiki/lib/Foswiki/Meta.pm line 968
	Foswiki::Meta::loadVersion('Foswiki::Meta=HASH(0xa7b31f8)', undef) called at /home/www/foswiki/lib/Foswiki/Meta.pm line 430
	Foswiki::Meta::load('Foswiki::Meta', 'Foswiki=HASH(0x8c051d8)', 'System', 'BulkResetPassword') called at /home/www/foswiki/lib/Foswiki/MetaCache.pm line 180
	Foswiki::MetaCache::get('Foswiki::MetaCache=HASH(0xa7857b0)', 'System', 'BulkResetPassword') called at /home/www/foswiki/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm line 230
	Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery('Foswiki::Query::Node=HASH(0xa7b0890)', 'System', undef, 'Foswiki=HASH(0x8c051d8)', 'HASH(0xa741a00)') called at /home/www/foswiki/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm line 78
	Foswiki::Store::QueryAlgorithms::BruteForce::query('Foswiki::Query::Node=HASH(0xa7b0890)', undef, 'Foswiki=HASH(0x8c051d8)', 'HASH(0xa741a00)') called at /home/www/foswiki/lib/Foswiki/Store/VC/Store.pm line 518
	Foswiki::Store::VC::Store::query('Foswiki::Store::RcsWrap=HASH(0x8c582f0)', 'Foswiki::Query::Node=HASH(0xa7b0890)', undef, 'Foswiki=HASH(0x8c051d8)', 'HASH(0xa741a00)') called at /home/www/foswiki/lib/Foswiki/Meta.pm line 839
	Foswiki::Meta::query('Foswiki::Query::Node=HASH(0xa7b0890)', undef, 'HASH(0xa741a00)') called at /home/www/foswiki/lib/Foswiki/Search.pm line 352
	Foswiki::Search::searchWeb('Foswiki::Search=HASH(0x969ce08)', 'search', 'info.date >= d2n(\'2009-01-01\') AND info.date <= d2n(\'2009-...', 'basetopic', 'Macros', '_RAW', '\x{a}  "info.date >= d2n(\'2009-01-01\') AND info.date <= d2n(\'2...', 'nonoise', 'on', ...) called at /home/www/foswiki/lib/Foswiki/Macros/SEARCH.pm line 32
	Foswiki::__ANON__() called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 379
	eval {...} called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 371
	Error::subs::try('CODE(0xa6a0cd8)', 'HASH(0xa7238a8)') called at /home/www/foswiki/lib/Foswiki/Macros/SEARCH.pm line 41
	Foswiki::SEARCH('Foswiki=HASH(0x8c051d8)', 'Foswiki::Attrs=HASH(0xa782870)', 'Foswiki::Meta=HASH(0x968e440)') called at /home/www/foswiki/lib/Foswiki.pm line 3145
	Foswiki::_expandMacroOnTopicRendering('Foswiki=HASH(0x8c051d8)', 'SEARCH', '\x{a}  "info.date >= d2n(\'2009-01-01\') AND info.date <= d2n(\'2...', 'Foswiki::Meta=HASH(0x968e440)') called at /home/www/foswiki/lib/Foswiki.pm line 3021
	Foswiki::_processMacros('Foswiki=HASH(0x8c051d8)', '%STARTINCLUDE%\x{a}---+ Macros\x{a}\x{a}_Special text strings expand on t...', 'CODE(0x8bac9b8)', 'Foswiki::Meta=HASH(0x968e440)', 16) called at /home/www/foswiki/lib/Foswiki.pm line 2818
	Foswiki::innerExpandMacros('Foswiki=HASH(0x8c051d8)', 'SCALAR(0x8bad438)', 'Foswiki::Meta=HASH(0x968e440)') called at /home/www/foswiki/lib/Foswiki.pm line 3327
	Foswiki::expandMacros('Foswiki=HASH(0x8c051d8)', '%STARTINCLUDE%\x{a}---+ Macros\x{a}\x{a}_Special text strings expand on t...', 'Foswiki::Meta=HASH(0x968e440)') called at /home/www/foswiki/lib/Foswiki/Meta.pm line 3103
	Foswiki::Meta::expandMacros('Foswiki::Meta=HASH(0x968e440)', '%STARTINCLUDE%\x{a}---+ Macros\x{a}\x{a}_Special text strings expand on t...') called at /home/www/foswiki/lib/Foswiki/UI/View.pm line 412
	Foswiki::UI::View::_prepare('%STARTINCLUDE%\x{a}---+ Macros\x{a}\x{a}_Special text strings expand on t...', 'Foswiki::Meta=HASH(0x968e440)', 0) called at /home/www/foswiki/lib/Foswiki/UI/View.pm line 392
	Foswiki::UI::View::view('Foswiki=HASH(0x8c051d8)') called at /home/www/foswiki/lib/Foswiki/UI.pm line 316
	Foswiki::UI::__ANON__() called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 379
	eval {...} called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 371
	Error::subs::try('CODE(0x8637958)', 'HASH(0x8c04f18)') called at /home/www/foswiki/lib/Foswiki/UI.pm line 435
	Foswiki::UI::_execute('Foswiki::Request=HASH(0x8bf1580)', 'CODE(0x8bcd688)', 'view', 1) called at /home/www/foswiki/lib/Foswiki/UI.pm line 274
	Foswiki::UI::handleRequest('Foswiki::Request=HASH(0x8bf1580)') called at /home/www/foswiki/lib/Foswiki/Engine/CGI.pm line 41
	Foswiki::Engine::CGI::run('Foswiki::Engine::CGI=HASH(0x8853b48)') called


----
   * Set PARENT = UserDocumentationCategory

         无法搜寻,错误: Error in tempfile() using /home/www/foswiki/working/tmp/XXXXXXXXXX: Could not create temp file /home/www/foswiki/working/tmp/kStZc6QovE: No space left on device at /home/www/foswiki/lib/Foswiki/Sandbox.pm line 506
 at /usr/share/perl5/File/Temp.pm line 1381
	File::Temp::tempfile('File::Temp', 'STDERR.20722.XXXXXXXXXX', 'DIR', '/home/www/foswiki/working/tmp', 'UNLINK', 0) called at /home/www/foswiki/lib/Foswiki/Sandbox.pm line 506
	Foswiki::Sandbox::sysCommand('Foswiki::Sandbox', '/usr/bin/rlog  -r%REVISION|N% %FILENAME|F%', 'REVISION', 1.2, 'FILENAME', '/home/www/foswiki/data/System/CommentPluginTemplate.txt,v') called at /home/www/foswiki/lib/Foswiki/Store/VC/RcsWrapHandler.pm line 323
	Foswiki::Store::VC::RcsWrapHandler::getInfo('Foswiki::Store::VC::RcsWrapHandler=HASH(0x96fb490)', undef) called at /home/www/foswiki/lib/Foswiki/Store/VC/Store.pm line 100
	Foswiki::Store::VC::Store::readTopic('Foswiki::Store::RcsWrap=HASH(0x8c582f0)', 'Foswiki::Meta=HASH(0x96fbb10)', undef) called at /home/www/foswiki/lib/Foswiki/Meta.pm line 968
	Foswiki::Meta::loadVersion('Foswiki::Meta=HASH(0x96fbb10)', undef) called at /home/www/foswiki/lib/Foswiki/Meta.pm line 430
	Foswiki::Meta::load('Foswiki::Meta', 'Foswiki=HASH(0x8c051d8)', 'System', 'CommentPluginTemplate') called at /home/www/foswiki/lib/Foswiki/MetaCache.pm line 180
	Foswiki::MetaCache::get('Foswiki::MetaCache=HASH(0xa7857b0)', 'System', 'CommentPluginTemplate') called at /home/www/foswiki/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm line 230
	Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery('Foswiki::Query::Node=HASH(0x9734510)', 'System', undef, 'Foswiki=HASH(0x8c051d8)', 'HASH(0xa6a0648)') called at /home/www/foswiki/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm line 78
	Foswiki::Store::QueryAlgorithms::BruteForce::query('Foswiki::Query::Node=HASH(0x9734510)', undef, 'Foswiki=HASH(0x8c051d8)', 'HASH(0xa6a0648)') called at /home/www/foswiki/lib/Foswiki/Store/VC/Store.pm line 518
	Foswiki::Store::VC::Store::query('Foswiki::Store::RcsWrap=HASH(0x8c582f0)', 'Foswiki::Query::Node=HASH(0x9734510)', undef, 'Foswiki=HASH(0x8c051d8)', 'HASH(0xa6a0648)') called at /home/www/foswiki/lib/Foswiki/Meta.pm line 839
	Foswiki::Meta::query('Foswiki::Query::Node=HASH(0x9734510)', undef, 'HASH(0xa6a0648)') called at /home/www/foswiki/lib/Foswiki/Search.pm line 352
	Foswiki::Search::searchWeb('Foswiki::Search=HASH(0x969ce08)', 'search', 'info.date >= d2n(\'2009-01-01\') AND info.date <= d2n(\'2009-...', 'basetopic', 'Macros', '_RAW', '\x{a}  "info.date >= d2n(\'2009-01-01\') AND info.date <= d2n(\'2...', 'nonoise', 'on', ...) called at /home/www/foswiki/lib/Foswiki/Macros/SEARCH.pm line 32
	Foswiki::__ANON__() called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 379
	eval {...} called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 371
	Error::subs::try('CODE(0xa6a0c08)', 'HASH(0xa72b830)') called at /home/www/foswiki/lib/Foswiki/Macros/SEARCH.pm line 41
	Foswiki::SEARCH('Foswiki=HASH(0x8c051d8)', 'Foswiki::Attrs=HASH(0xa741a80)', 'Foswiki::Meta=HASH(0x968e440)') called at /home/www/foswiki/lib/Foswiki.pm line 3145
	Foswiki::_expandMacroOnTopicRendering('Foswiki=HASH(0x8c051d8)', 'SEARCH', '\x{a}  "info.date >= d2n(\'2009-01-01\') AND info.date <= d2n(\'2...', 'Foswiki::Meta=HASH(0x968e440)') called at /home/www/foswiki/lib/Foswiki.pm line 3021
	Foswiki::_processMacros('Foswiki=HASH(0x8c051d8)', '%STARTINCLUDE%\x{a}---+ Macros\x{a}\x{a}_Special text strings expand on t...', 'CODE(0x8bac9b8)', 'Foswiki::Meta=HASH(0x968e440)', 16) called at /home/www/foswiki/lib/Foswiki.pm line 2818
	Foswiki::innerExpandMacros('Foswiki=HASH(0x8c051d8)', 'SCALAR(0x8bad438)', 'Foswiki::Meta=HASH(0x968e440)') called at /home/www/foswiki/lib/Foswiki.pm line 3327
	Foswiki::expandMacros('Foswiki=HASH(0x8c051d8)', '%STARTINCLUDE%\x{a}---+ Macros\x{a}\x{a}_Special text strings expand on t...', 'Foswiki::Meta=HASH(0x968e440)') called at /home/www/foswiki/lib/Foswiki/Meta.pm line 3103
	Foswiki::Meta::expandMacros('Foswiki::Meta=HASH(0x968e440)', '%STARTINCLUDE%\x{a}---+ Macros\x{a}\x{a}_Special text strings expand on t...') called at /home/www/foswiki/lib/Foswiki/UI/View.pm line 412
	Foswiki::UI::View::_prepare('%STARTINCLUDE%\x{a}---+ Macros\x{a}\x{a}_Special text strings expand on t...', 'Foswiki::Meta=HASH(0x968e440)', 0) called at /home/www/foswiki/lib/Foswiki/UI/View.pm line 392
	Foswiki::UI::View::view('Foswiki=HASH(0x8c051d8)') called at /home/www/foswiki/lib/Foswiki/UI.pm line 316
	Foswiki::UI::__ANON__() called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 379
	eval {...} called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 371
	Error::subs::try('CODE(0x8637958)', 'HASH(0x8c04f18)') called at /home/www/foswiki/lib/Foswiki/UI.pm line 435
	Foswiki::UI::_execute('Foswiki::Request=HASH(0x8bf1580)', 'CODE(0x8bcd688)', 'view', 1) called at /home/www/foswiki/lib/Foswiki/UI.pm line 274
	Foswiki::UI::handleRequest('Foswiki::Request=HASH(0x8bf1580)') called at /home/www/foswiki/lib/Foswiki/Engine/CGI.pm line 41
	Foswiki::Engine::CGI::run('Foswiki::Engine::CGI=HASH(0x8853b48)') called


----
   * Set PARENT = UserDocumentationCategory

See also: FormattedSearch

Macro Names

Macro names must start with a letter. The following characters can be letters, numbers and the underscore '_'. Letters may be upper or lower-case, E.g. %MYVAR%, %MyVar%, %My2ndVar%, and %My_Var% are all separate, valid macro names (macros are case sensitive - %MyVAR% and %MYVAR% are not the same).

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

Preference Settings

A preference setting lets you define a simple macro that will be expanded in your output. A preference setting looks like this:

[multiple of 3 spaces] * [space] Set [space] MACRONAME [space] = [space] value

Example:

   * Set WEBBGCOLOR = #FFFFC0
Macros defined using preference settings are expanded by enclosing their name in percent signs. So when you write %WEBBGCOLOR%, it gets expanded to #FFD8AA

A preference macro is always taken from the most current topic revision, even when accessing previous revisions of a topic.

Preferences can be defined in a number of places:
  1. DefaultPreferences (Foswiki upgrades overwrite this topic)
  2. In (some) plugin documentation topics. (Deprecated)
  3. SitePreferences
  4. In user topics, if the user has one (yours is Main.WikiGuest)
  5. WebPreferences
  6. Sub-webs inherit the WebPreferences of their parent
  7. In the topic being accessed
In this list, Set statements which occur at numerically higher locations override macros of the same name defined at lower numbered levels, unless the macro was listed in a finalpreferences setting (finalised) at a lower-numbered level. in this case, the macro is locked to the value at that level; set statements at higher-numbered levels are ignored.

prefs-stack.jpg

IDEA! preference settings can easily be disabled with a # sign. Example:
   * #Set DENYWEBCHANGE = %USERSWEB%.UnknownUser
IDEA! You can hide preference settings in the output by enclosing them in HTML comments; for example,
<!--
   * Set HIDDEN = This will be invisible in the output
-->

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 setting anywhere in the topic, even if you set it at the very 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.

Also note that Foswiki always reads the setting from the most current topic revision, so viewing older revisions of a topic can show unexpected results.

And especially important, preference settings are never overridden or set in "%INCLUDE{" topics. in the below example about weather conditions, note the difference in the CONDITIONS expansion

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 (though see Parameters, below).

Example: Create a custom logo macro
  • To place a logo anywhere in a web by typing %MYLOGO%, define the preference settings in the web's WebPreferences topic, and upload a logo file, ex: mylogo.gif. You can upload by 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:
   * Set MYLOGO = %PUBURL%/%WEB%/LogoTopic/mylogo.gif

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 known as 'meta' preferences and are not visible in the topic text, but take effect nevertheless.

Parameters

Note that %CONDITIONS% expands differently when this example is viewed in PreferenceSettings. This is because Set statement are not active in included topics. The including topic's set statements are used.

Macros defined using preference settings can take parameters. These are symbols passed in the call to the macro to define local macros that will be expanded in the output. For example,
   * Set CONDITIONS = According to [[%BASETOPIC%]] the %WHAT% is %STATE% today (Set in ...).
You can call this macro passing in values for WHAT and STATE. For example:
  • %CONDITIONS{WHAT="sea" STATE="choppy"}%
    • expands to According to Macros, The sea is choppy today. (Set in Macros)..

Parameter defaults

  • The special parameter name DEFAULT gets the value of any unnamed parameter in the macro call.
  • Parameter macros can accept a default parameter so that they expand to something even when a value isn't passed for them in the call.
Example:
   * Set WEATHER = It's %DEFAULT{default="raining"}%.
  • %WEATHER% expands to It's raining.
  • %WEATHER{"sunny"}% expands to It's sunny.
The standard formatting tokens can be used in parameters. They will be expanded immediately when the macro is instantiated.

ALERT! Note that parameters override all other macros, including system defined macros, in the expansion of the macro where they are used.

Access Control Settings

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

Local values for preferences

Certain topics (user, plugin, 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.

ALERT! Predefined macros can be overridden by preference settings (except TOPIC and WEB)

ALERT! Plugins may extend the set of predefined macros (see individual Plugins topics for details)

TIP 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 %BASETOPIC%, %INCLUDE%, and the mighty %SEARCH%.

Your installation of Foswiki v1.1.8 has the following registered macros:

无法搜寻,错误
Error in tempfile() using /home/www/foswiki/working/tmp/XXXXXXXXXX: Could not create temp file /home/www/foswiki/working/tmp/wNmEdpS0dk: No space left on device at /home/www/foswiki/lib/Foswiki/Sandbox.pm line 506 at /usr/share/perl5/File/Temp.pm line 1381 File::Temp::tempfile('File::Temp', 'STDERR.20722.XXXXXXXXXX', 'DIR', '/home/www/foswiki/working/tmp', 'UNLINK', 0) called at /home/www/foswiki/lib/Foswiki/Sandbox.pm line 506 Foswiki::Sandbox::sysCommand('Foswiki::Sandbox', '/usr/bin/rlog -r%REVISION|N% %FILENAME|F%', 'REVISION', 1.2, 'FILENAME', '/home/www/foswiki/data/System/VarEDITTABLE.txt,v') called at /home/www/foswiki/lib/Foswiki/Store/VC/RcsWrapHandler.pm line 323 Foswiki::Store::VC::RcsWrapHandler::getInfo('Foswiki::Store::VC::RcsWrapHandler=HASH(0xa806d40)', undef) called at /home/www/foswiki/lib/Foswiki/Store/VC/Store.pm line 100 Foswiki::Store::VC::Store::readTopic('Foswiki::Store::RcsWrap=HASH(0x8c582f0)', 'Foswiki::Meta=HASH(0xa854228)', undef) called at /home/www/foswiki/lib/Foswiki/Meta.pm line 968 Foswiki::Meta::loadVersion('Foswiki::Meta=HASH(0xa854228)', undef) called at /home/www/foswiki/lib/Foswiki/Meta.pm line 430 Foswiki::Meta::load('Foswiki::Meta', 'Foswiki=HASH(0x8c051d8)', 'System', 'VarEDITTABLE') called at /home/www/foswiki/lib/Foswiki/MetaCache.pm line 180 Foswiki::MetaCache::get('Foswiki::MetaCache=HASH(0xa7857b0)', 'System', 'VarEDITTABLE') called at /home/www/foswiki/lib/Foswiki/Search.pm line 783 Foswiki::Search::formatResults('Foswiki::Search=HASH(0x969ce08)', 'Foswiki::Search::Node=HASH(0xa7b59b8)', 'Foswiki::Search::ResultSet=HASH(0xa83a0a8)', 'HASH(0xa785490)') called at /home/www/foswiki/lib/Foswiki/Search.pm line 410 Foswiki::Search::searchWeb('Foswiki::Search=HASH(0x969ce08)', 'casesensitive', 'on', 'search', '^Var[A-Z_0-9]+$', 'basetopic', 'Macros', '_RAW', '\x{a} "^Var[A-Z_0-9]+$"\x{a} casesensitive="on"\x{a} web="System...', ...) called at /home/www/foswiki/lib/Foswiki/Macros/SEARCH.pm line 32 Foswiki::__ANON__() called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 379 eval {...} called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 371 Error::subs::try('CODE(0xa6a5700)', 'HASH(0xa6a0de8)') called at /home/www/foswiki/lib/Foswiki/Macros/SEARCH.pm line 41 Foswiki::SEARCH('Foswiki=HASH(0x8c051d8)', 'Foswiki::Attrs=HASH(0xa6a5720)', 'Foswiki::Meta=HASH(0x968e440)') called at /home/www/foswiki/lib/Foswiki.pm line 3145 Foswiki::_expandMacroOnTopicRendering('Foswiki=HASH(0x8c051d8)', 'SEARCH', '\x{a} "^Var[A-Z_0-9]+$"\x{a} casesensitive="on"\x{a} web="System...', 'Foswiki::Meta=HASH(0x968e440)') called at /home/www/foswiki/lib/Foswiki.pm line 3021 Foswiki::_processMacros('Foswiki=HASH(0x8c051d8)', '%STARTINCLUDE%\x{a}---+ Macros\x{a}\x{a}_Special text strings expand on t...', 'CODE(0x8bac9b8)', 'Foswiki::Meta=HASH(0x968e440)', 16) called at /home/www/foswiki/lib/Foswiki.pm line 2818 Foswiki::innerExpandMacros('Foswiki=HASH(0x8c051d8)', 'SCALAR(0x8bad438)', 'Foswiki::Meta=HASH(0x968e440)') called at /home/www/foswiki/lib/Foswiki.pm line 3327 Foswiki::expandMacros('Foswiki=HASH(0x8c051d8)', '%STARTINCLUDE%\x{a}---+ Macros\x{a}\x{a}_Special text strings expand on t...', 'Foswiki::Meta=HASH(0x968e440)') called at /home/www/foswiki/lib/Foswiki/Meta.pm line 3103 Foswiki::Meta::expandMacros('Foswiki::Meta=HASH(0x968e440)', '%STARTINCLUDE%\x{a}---+ Macros\x{a}\x{a}_Special text strings expand on t...') called at /home/www/foswiki/lib/Foswiki/UI/View.pm line 412 Foswiki::UI::View::_prepare('%STARTINCLUDE%\x{a}---+ Macros\x{a}\x{a}_Special text strings expand on t...', 'Foswiki::Meta=HASH(0x968e440)', 0) called at /home/www/foswiki/lib/Foswiki/UI/View.pm line 392 Foswiki::UI::View::view('Foswiki=HASH(0x8c051d8)') called at /home/www/foswiki/lib/Foswiki/UI.pm line 316 Foswiki::UI::__ANON__() called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 379 eval {...} called at /home/www/foswiki/lib/CPAN/lib/Error.pm line 371 Error::subs::try('CODE(0x8637958)', 'HASH(0x8c04f18)') called at /home/www/foswiki/lib/Foswiki/UI.pm line 435 Foswiki::UI::_execute('Foswiki::Request=HASH(0x8bf1580)', 'CODE(0x8bcd688)', 'view', 1) called at /home/www/foswiki/lib/Foswiki/UI.pm line 274 Foswiki::UI::handleRequest('Foswiki::Request=HASH(0x8bf1580)') called at /home/www/foswiki/lib/Foswiki/Engine/CGI.pm line 41 Foswiki::Engine::CGI::run('Foswiki::Engine::CGI=HASH(0x8853b48)') called

Shortcuts

The following macros are preference settings and are frequently used in topic content.
  • %BR% - line break
  • %BULLET% - bullet sign
  • %BB% - line break and bullet combined
  • %BB2% - indented line break and bullet
  • %RED% text %ENDCOLOR% - colored text (also %YELLOW%, %ORANGE%, %PINK%, %PURPLE%, %TEAL%, %NAVY%, %BLUE%, %AQUA%, %LIME%, %GREEN%, %OLIVE%, %MAROON%, %BROWN%, %BLACK%, %GRAY%, %SILVER%, %WHITE%)
  • %H% - HELP Help icon
  • %I% - IDEA! Idea icon
  • %M% - MOVED TO... Moved to icon
  • %N% - NEW New icon
  • %P% - REFACTOR Refactor icon
  • %Q% - QUESTION? Question icon
  • %S% - PICK Red star icon
  • %T% - TIP Tip icon
  • %U% - UPDATED Updated icon
  • %X% - ALERT! Alert icon
  • %Y% - DONE Done icon

See ShortcutMacros for a full list of predefined shortcuts.


Related Topics: UserDocumentationCategory
主题版本: r1 - 2011-10-09, ProjectContributor
 
This site is powered by Foswiki版权所有 © 所有作者。本合作平台的所有资料归内容提贡者所有。
回馈有关 HEPG 的建议、需求及问题。