%META:TOPICINFO{author="ProjectContributor" comment="" date="1655468868" format="1.1" version="1"}%
%META:TOPICPARENT{name="UserDocumentationCategory"}%
%STARTINCLUDE%
---+ Macros

Special text strings expand on the fly to display information, or trigger a function.

Macros are text strings in one of three basic forms:

<verbatim class="tml">
%MACRONAME%
%MACRONAME{ parameter="value" }%
%MACRONAME{
  param1="value "
        +"& more "
  param2="whatever"
  param1+="and even more"
}%
</verbatim>

The third form is a new feature in Foswiki 2.1 to significantly improve readability with complex macros, see [[#Readable_Macros][Readable Macros]] for details.

These usually expand into content when a topic is rendered for viewing. There are two types of macros:
   1 [[PreferenceSettings][Preference settings]]: May be defined and modified by the user
   1 Registered 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][predefined preference setting]])
   * type =%<nop>TOPIC%= to get =%TOPIC%= (a predefined [[VarTOPIC][macro]])
   * type =%<nop>CALC{ "$UPPER(Text)" }%= to get =TEXT= ([[VarCALC][CALC]] is a macro defined by [[SpreadSheetPlugin]])

*Note:*
   * To leave a macro unexpanded, precede it with an exclamation mark, e.g. type =!%<nop>TOPIC%= to get =%<nop>TOPIC%=
      * Alternatively, insert a =&lt;nop&gt;= anywhere in the macro, Eg. =%&lt;nop&gt;TOPIC%=
   * Macros are expanded relative to the topic they are _used_ in, not the topic they are _defined_ in
   * Type =%<nop>SHOWPREFERENCE%= to get a full listing of all macros defined for a particular topic, or =%<nop>SHOWPREFERENCE{"foo"}%= to see an individual setting.
   * 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, =%<nop>UNDEFINED{default="blank"}%= will expand to =blank=.

---+++ Order of expansion
The following describes only these types of macros:
   * [[PreferenceSettings][Preference settings]]
   * Most macros provided by plugins (notable exceptions include [[VarCALC][CALC]], [[VarTABLE][TABLE]] and any other macros that are expanded in =commonTagsHandler()=)
   * Most built-in Foswiki macros (exceptions include [[VarTOC][TOC]] and macros that have start/stop parts e.g: [[VarSTARTSECTION][STARTSECTION]]/ENDSECTION, [[VarSTARTINCLUDE][STARTINCLUDE]]/STOPINCLUDE)

%STARTSECTION{"insideoutlefttoright"}%
#StandardForm
---++++ Standard form
#InsideOutLeftToRight
The key to understanding nested expressions in Foswiki is to understand that macros are expanded "inside-out, left-to-right". *Example:*

<verbatim class="tml">
%MACRO1{
   something="%MACRO2{
      somethingelse="%MACRO3%, %MACRO4%"
   }%"
}%
</verbatim>
The macros are expanded in this order: MACRO3, MACRO4, MACRO2, MACRO1.

---+++++ Step-by-Step Example

%TABPANE{class="plain" animate="on"}%
%TAB{"Step 1"}%
<pre class="tml">
%<nop>INCLUDE{
    "%<nop>QUERY{
        "'%<nop>THETOPIC%'/%<nop>THEFIELD%"
    }%"
    section="Summary"
}%
   * Set THETOPIC = %<nop>SYSTEMWEB%.FAQWhatIsWikiWiki
   * Set THEFIELD = TopicClassification
</pre>
%ENDTAB%
%TAB{"Step 2"}%
<pre class="tml">
%<nop>INCLUDE{
    "%<nop>QUERY{
        "'%<nop>SYSTEMWEB%.FAQWhatIsWikiWiki'/%<nop>THEFIELD%"
    }%"
    section="Summary"
}%
   * Set THETOPIC = %<nop>SYSTEMWEB%.FAQWhatIsWikiWiki
   * Set THEFIELD = TopicClassification
</pre>
%ENDTAB%
%TAB{"Step 3"}%
<pre class="tml">
%<nop>INCLUDE{
    "%<nop>QUERY{
        "'%<nop>SYSTEMWEB%.FAQWhatIsWikiWiki'/TopicClassification"
    }%"
    section="Summary"
}%
   * Set THETOPIC = %<nop>SYSTEMWEB%.FAQWhatIsWikiWiki
   * Set THEFIELD = TopicClassification
</pre>
%ENDTAB%
%TAB{"Step 4"}%
<pre class="tml">
%<nop>INCLUDE{
    "%<nop>QUERY{
        "'%SYSTEMWEB%.FAQWhatIsWikiWiki'/TopicClassification"
    }%"
    section="Summary"
}%
   * Set THETOPIC = %<nop>SYSTEMWEB%.FAQWhatIsWikiWiki
   * Set THEFIELD = TopicClassification
</pre>
%ENDTAB%
%TAB{"Step 5"}%
<pre class="tml">
%<nop>INCLUDE{
    "%QUERY{
        "'%SYSTEMWEB%.FAQWhatIsWikiWiki'/TopicClassification"
    }%"
    section="Summary"
}%
   * Set THETOPIC = %<nop>SYSTEMWEB%.FAQWhatIsWikiWiki
   * Set THEFIELD = TopicClassification
</pre>
%ENDTAB%
%TAB{"Step 6"}%
<pre class="tml">
%INCLUDE{
    "%QUERY{
        "'%SYSTEMWEB%.FAQWhatIsWikiWiki'/TopicClassification"
    }%"
    section="Summary"
}%
   * Set THETOPIC = %<nop>SYSTEMWEB%.FAQWhatIsWikiWiki
   * Set THEFIELD = TopicClassification
</pre>
%ENDTAB%
%TAB{"Step 7"}%
<pre class="tml">
%INCLUDE{
    "%QUERY{
        "'%SYSTEMWEB%.FAQWhatIsWikiWiki'/TopicClassification"
    }%"
    section="Summary"
}%
   * Set THETOPIC = %SYSTEMWEB%.FAQWhatIsWikiWiki
   * Set THEFIELD = TopicClassification
</pre>
%ENDTAB%
%ENDTABPANE%

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

%STARTSECTION{"tokensupport"}%<div class="foswikiHelp">
  %T% When working with a given [[Macros][macro]], consult its documentation to determine which parameters support the =$percent/$percnt= [[FormatTokens][format tokens]]. Generally only _output parameters_ like =header=, =format= and =footer= support [[FormatTokens][format tokens]].
  </div>%ENDSECTION{"tokensupport"}%
*Example:*
<verbatim class="tml">
%MACRO1{
   format="$percentMACRO2{
      format=\"%MACRO3%, %MACRO4%\"
   }$percent"
}%
</verbatim>
The macros are expanded in this order: MACRO3, MACRO4, MACRO1, *MACRO2*.

---+++++ Step-by-Step Example

From the [[FormattedSearch#ConditionalOutputExample][conditional output example]]:

%TABPANE{class="plain" animate="on"}%
%TAB{"Step 1"}%
<verbatim class="tml">
%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
</verbatim>
%ENDTAB%
%TAB{"Step 2"}%
<pre class="tml">
%<nop>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
</pre>
%ENDTAB%
%TAB{"Step 3" url="%SCRIPTURLPATH{"view"}%/%WEB%/%TOPIC%?skin=text&section=step3"}%
%ICON{"processing"}%
<verbatim class="foswikiHidden">
%STARTSECTION{"step3"}%
<pre class="tml">
%SEARCH{
  "info.date >= d2n('2009-01-01') AND info.date <= d2n('2009-12-31')"
  type="query"
  limit="2"
  nonoise="on"
  format="   * $percent<nop>ICON{
    \"$percent<nop>IF{
      \"'$topic'/parent.name='UserDocumentationCategory'\"
      then=\"info\" else=\"gear\"
    }$percent\"
  }$percent [[$topic]]"
}%
----
   * Set PARENT = UserDocumentationCategory
</pre>
%ENDSECTION{"step3"}%
</verbatim>
%ENDTAB%
%TAB{"Step 4" url="%SCRIPTURLPATH{"view"}%/%WEB%/%TOPIC%?skin=text&section=step4"}%
%ICON{"processing"}%
<verbatim class="foswikiHidden">
%STARTSECTION{"step4"}%
<pre class="tml">
%SEARCH{
  "info.date >= d2n('2009-01-01') AND info.date <= d2n('2009-12-31')"
  type="query"
  limit="2"
  nonoise="on"
  format="   * $percent<nop>ICON{
    \"$percentIF{
      \"'$topic'/parent.name='UserDocumentationCategory'\"
      then=\"info\" else=\"gear\"
    }$percent\"
  }$percent [[$topic]]"
}%
----
   * Set PARENT = UserDocumentationCategory
</pre>
%ENDSECTION{"step4"}%
</verbatim>
%ENDTAB%
%TAB{"Step 5" url="%SCRIPTURLPATH{"view"}%/%WEB%/%TOPIC%?skin=text&section=step5"}%
%ICON{"processing"}%
<verbatim class="foswikiHidden">
%STARTSECTION{"step5"}%
<pre class="tml">
%SEARCH{
  "info.date >= d2n('2009-01-01') AND info.date <= d2n('2009-12-31')"
  type="query"
  limit="2"
  nonoise="on"
  format="   * &lt;img src=\"$percentICONURL{
    \"$percentIF{
      \"'$topic'/parent.name='UserDocumentationCategory'\"
      then=\"info\" else=\"gear\"
    }$percent\"
  }$percent\"/&gt; [[$topic]]"
}%
----
   * Set PARENT = UserDocumentationCategory
</pre>
%ENDSECTION{"step5"}%
</verbatim>
%ENDTAB%
%ENDTABPANE%
%ENDSECTION{"insideoutlefttoright"}%

See also: [[FormattedSearch#NestedSearchExample][FormattedSearch]]

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

By convention all settings, predefined macros and macros registered by plugins are always UPPER-CASE.
<!--
   * Set CONDITIONS = According to [[%TOPIC%]], The %WHAT% is %STATE% today. (Set in [[Macros]]).
   * Set WEATHER = It's %DEFAULT{default="raining"}%.
-->
%INCLUDE{"PreferenceSettings"}%

#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.

<div class="foswikiHelp">
%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%=.
</div>

%IF{"'%INCLUDINGTOPIC%'!='CompleteDocumentation'" then="See MacrosQuickReference for a complete list of predefined macros in your installation."}%

---++ Readable Macros

Some macros can become quite complex and, as such, hard to read. Over the years changes have been made to make this easier. For some time it has been possible to break a macro over multiple lines. Nonetheless, each parameter can easily extend onto many lines (it can after all be another macro). In general Foswiki allows lines to be continued by ending a line with a =\= character. This is generally useful but with macros you need precise control of spaces which =\= does not give you.

From Foswiki 2.1 it's now possible to use the following in macros to make them much more readable:
   * =parameter="value" +"more" +"and more"=
   * =param1+="value1" param2+="value2" param1+="more1" param2+="more2"=

Once upon a time in the early days of the project the parameters to SEARCH would need to be written as one line of TML, an example from an active Foswiki site:
<verbatim class="tml">
type="query" nonoise="on" web="Batch" header="|*Batch Code*|*Batch Value*|*Currencies*|*Sizes*|*Count*|*To Queue*|*Killed*|*Ignored*|*Errors*|*Notes*|*History*|*Flow*|" format="| [[$topic][$formfield(BatchCode) $formfield(BatchDate) $formfield(BatchNumber) $formfield(BatchLocation)]]"}$percnt | $formfield(BatchValue) | $formfield(BatchCurrencies) | $formfield(BatchSizes) | $formfield(BatchCount) | $formfield(BatchToQueue) | $formfield(BatchKilled) | $formfield(BatchIgnored) | <div style='background-color:#$percntCALC{$SET(dat,$formfield(BatchDate))$SET(pdat,$formfield(BatchProcessDate))$SET(age,$EVAL($percnt$formfield(BatchCode)_days$percnt))$IF($EXACT($percntWORKFLOWSTATE{\"$topic\"}$percnt,CHECKED),FAF0D4,$IF($GET(age)>=0,ff3300,$IF($GET(age)>=-2,ff9933,66cc33)))}$percnt'>$formfield(BatchErrors)&nbsp;</div> | $formfield(BatchOperators) | $formfield(BatchActivities) | <form name=\"Edit\" action=\"%SCRIPTURLPATH{edit}%/%WEB%/\"> <input type=\"hidden\" name=\"action\" value=\"form\"/> <input type=\"hidden\" name=\"topic\" value=\"$topic\"/> <input type=\"hidden\" name=\"redirectto\" value=\"%TOPIC%?%QUERYSTRING{encode="url"}%\"/> <input type=\"image\" src=\"%ICONURL{pencil}%\" alt=\"Edit Form\" /> </form> $formfield(BatchNotes) | $percntWORKFLOWHISTORY{\"$topic\"}$percnt | $percntWORKFLOWTRANSITION{\"$topic\" redirectto=\"%TOPIC%?%QUERYSTRING{encode="url"}%\"}$percnt |"
</verbatim>

That is very hard to read and debug, and even harder to maintain months or years later and for readability this example excludes the complex and many line =search= parameter.

Now, we can improve that by splitting each parameter onto a separate line:
<verbatim class="tml">
  type="query"
  nonoise="on"
  web="Batch"
  header="|*Batch Code*|*Batch Value*|*Currencies*|*Sizes*|*Count*|*To Queue*|*Killed*|*Ignored*|*Errors*|*Notes*|*History*|*Flow*|"
  format="| [[$topic][$formfield(BatchCode) $formfield(BatchDate) $formfield(BatchNumber) $formfield(BatchLocation)]] | $formfield(BatchValue) | $formfield(BatchCurrencies) | $formfield(BatchSizes) | $formfield(BatchCount) | $formfield(BatchToQueue) | $formfield(BatchKilled) | $formfield(BatchIgnored) | <div style='background-color:#$percntCALC{$SET(dat,$formfield(BatchDate))$SET(pdat,$formfield(BatchProcessDate))$SET(age,$EVAL($percnt$formfield(BatchCode)_days$percnt))$IF($EXACT($percntWORKFLOWSTATE{\"$topic\"}$percnt,CHECKED),FAF0D4,$IF($GET(age)>=0,ff3300,$IF($GET(age)>=-2,ff9933,66cc33)))}$percnt'>$formfield(BatchErrors)&nbsp;</div> | $formfield(BatchOperators) | $formfield(BatchActivities) | <form name=\"Edit\" action=\"%SCRIPTURLPATH{edit}%/%WEB%/\"> <input type=\"hidden\" name=\"action\" value=\"form\"/> <input type=\"hidden\" name=\"topic\" value=\"$topic\"/> <input type=\"hidden\" name=\"redirectto\" value=\"%TOPIC%?%QUERYSTRING{encode="url"}%\"/> <input type=\"image\" src=\"%ICONURL{pencil}%\" alt=\"Edit Form\" /> </form> $formfield(BatchNotes) | $percntWORKFLOWHISTORY{\"$topic\"}$percnt | $percntWORKFLOWTRANSITION{\"$topic\" redirectto=\"%TOPIC%?%QUERYSTRING{encode="url"}%\"}$percnt |"
</verbatim>

That helps a little, but the =format= parameter still covers multiple lines and is still hard to follow.

Now we could use the standard Foswiki line continuation, but you do not get full control of spacing and you cannot achieve the result you want. In the example above, which creates a table, one possible problem is having cell values centred instead of right justified.

This is when the ability to cleanly separate comes into its own. This is achieved by using the =+"more"= option to break a parameter into appropriate pieces, we can now transform the above to:
<verbatim class="tml">
  type="query"
  nonoise="on"
  web="Batch"
  header=""
        +"|*Batch Code*"
        +"|*Batch Value*"
        +"|*Currencies*"
        +"|*Sizes*"
        +"|*Count*"
        +"|*To Queue*"
        +"|*Killed*"
        +"|*Ignored*"
        +"|*Errors*"
        +"|*Notes*"
        +"|*History*"
        +"|*Flow*"
        +"|"
  format=""
        +"| [[$topic][$formfield(BatchCode) $formfield(BatchDate) $formfield(BatchNumber) $formfield(BatchLocation)]]"
        +"| $formfield(BatchValue) "
        +"| $formfield(BatchCurrencies) "
        +"| $formfield(BatchSizes) "
        +"| $formfield(BatchCount) "
        +"| $formfield(BatchToQueue) "
        +"| $formfield(BatchKilled) "
        +"| $formfield(BatchIgnored) "
        +"| <div style='background-color:#"
        +"$percntCALC{"
        +"$SET(dat,$formfield(BatchDate))"
        +"$SET(pdat,$formfield(BatchProcessDate))"
        +"$SET(age,$EVAL($percnt$formfield(BatchCode)_days$percnt))"
        +"$IF($EXACT($percntWORKFLOWSTATE{\"$topic\"}$percnt,CHECKED),FAF0D4,"
        +"$IF($GET(age)>=0,ff3300,$IF($GET(age)>=-2,ff9933,66cc33)))}"
        +"$percnt'>$formfield(BatchErrors)&nbsp;</div> "
        +"| $formfield(BatchOperators) "
        +"| $formfield(BatchActivities) "
        +"| <form name=\"Edit\" action=\"%SCRIPTURLPATH{edit}%/%WEB%/\">"
        +"<input type=\"hidden\" name=\"action\" value=\"form\"/>"
        +"<input type=\"hidden\" name=\"topic\" value=\"$topic\"/>"
        +"<input type=\"hidden\" name=\"redirectto\" value=\"%TOPIC%?%QUERYSTRING{encode="url"}%\"/>"
        +"<input type=\"image\" src=\"%ICONURL{pencil}%\" alt=\"Edit Form\" /> </form> $formfield(BatchNotes) "
        +"| $percntWORKFLOWHISTORY{\"$topic\"}$percnt "
        +"| $percntWORKFLOWTRANSITION{\"$topic\" redirectto=\"%TOPIC%?%QUERYSTRING{encode="url"}%\"}$percnt "
        +"|"
</verbatim>

Note the use of =+= to concatenate all the pieces of the =format= and =header= parameters together. Also note that each piece is of the form =+"more"= and as that is quoted you have full control of the contents. This is especially true for those all important spaces &mdash; you'll see some pieces have a trailing space and some do not.

<div class="foswikiHelp">
%T% parameter="value" +" and more"       &mdash; is quite valid on one line if its useful

%X% parameter="1" +"2" gives you "12" *not* "3"
</div>

Both the =header= and =format= parameters above start each table cell on a separate line. This makes it a little easier to scan the topic text the match the cell positions and check they line up (i.e. the Header cell #n will match the contents from Format cell #n).

Another trick used above for easier maintenance is to initialise a parameter to =""= and then add the pieces on separate lines. (In the example we are dealing with table cells hence ="|"=, on a separate line, is used as an end of row marker.) This helps by allowing you to cut and paste whole lines, representing cells, into different column positions without concern as to whether or not it's the 1st column, last column or one in the middle because they have an identical structure.

Nonetheless, keeping the =header= of a table column separate from the =format= of each cell in the SEARCH can still be troublesome especially as the number of columns and/or complexity of =header= and =footer= cells grow.

To remedy that the =param1+="value1" param2="value2" param1+="more1" param2+="more2"= can be used. Not that the pieces of different parameters can now be intermingled in whatever way you need to make the macro easier to read. For example we can transform the above to:
<verbatim class="tml">
  type="query"
  nonoise="on"
  web="Batch"

  header+="|*Control record*"
  format+="| <span style=\"display:none;\">"
         +"$formfield(BatchNumber) $formfield(BatchLocation) "
         +"$percntCALC{$SUBSTRING($topic,13,3)}$percnt $formfield(BatchDate) "
         +"!$formfield(BatchCode)"
         +"</span>"
         +"<a id=\"$topic\"/>[[$topic]]"

  header+="|*Batch Value*"
  format+="|  $formfield(BatchValue) "

  header+="|*Batch Curr- encies*"
  format+="| $formfield(BatchCurrencies) "

  header+="|*Success*"
  format+="|  $formfield(BatchCount) "

  header+="|*To Queue*"
  format+="|  $formfield(BatchToQueue) "

  header+="|*Killed*"
  format+="|  $formfield(BatchKilled) "

  header+="|*Ignored*"
  format+="|  $formfield(BatchIgnored) "

  header+="|*Batch Size*"
  format+="|  $formfield(BatchSizes) "

  header+="|*Batch Errors*"
  format+="| <div style='background-color:#"
         +"$percntCALC{$SET(dat,$formfield(BatchDate))"
         +"$SET(pdat,$formfield(BatchProcessDate))"
         +"$SET(age,$EVAL($percnt$formfield(BatchCode)_days$percnt))"
         +"$IF($EXACT($percntWORKFLOWSTATE{\"$topic\"}$percnt,CHECKED),FAF0D4,"
         +"$IF($GET(age)>=0,ff3300,$IF($GET(age)>=-2,ff9933,66cc33)))}$percnt'>"
         +"$formfield(BatchErrors) </div> "

  header+="|*Batch Oper- ators*"
  format+="| $formfield(BatchOperators) "

  header+="|*Batch Acti- vities*"
  format+="| $formfield(BatchActivities) "

  header+="|*Batch Notes*"
  format+="| <form name=\"Edit\" action=\"%SCRIPTURLPATH{edit}%/%WEB%/\">"
         +"<input type=\"hidden\" name=\"action\" value=\"form\"/>"
         +"<input type=\"hidden\" name=\"topic\" value=\"$topic\"/>"
         +"<input type=\"hidden\" name=\"redirectto\" value=\"%TOPIC%?%QUERYSTRING%#$topic\"/>"
         +"<input type=\"image\" src=\"%ICONURL{pencil}%\" alt=\"Edit Form\" /> </form> $formfield(BatchNotes)"

  header+="|*Status History*"
  format+="| $percntWORKFLOWHISTORY{\"$topic\"}$percnt "

  header+="|*Change Status*"
  format+="| $percntWORKFLOWTRANSITION{\"$topic\" redirectto=\"%TOPIC%?%QUERYSTRING%#$topic\"}$percnt "

  header+="|"
  format+="|"
</verbatim>

There is no guesswork (or cell counting) required to work out which cell =header= matches which =format= cell. Also note how this enables you to better manage table layouts by keeping the coding for each column together and in turn the easy ability to move a column into other positions by cut and paste.

The 1st parameter in a macro does not have to be named, e.g =%<nop>MACRO{"I'm the first"}%=. How can you extend such a value with =name+="more"= when it has no name? Well actually it does and it's name is =_DEFAULT= so you can have =%<nop>MACRO{"I'm the first" type="X" _DEFAULT+=", with seconds"}%=. Some macros may give you an alternative name to use, e.g. =%SEARCH= allows =search= i.e. =%<nop>SEARCH{search="find him" type="literal" search+=" and her"}%=. In this situation it is better to use one or the other and not both as that could lead to confusion. In the case of =%SEARCH= if you use both then this macro will ignore =search= and use =_DEFAULT=, so take care.

The following is a working example using the Foswiki FAQ topics follows. You can use this to create yourself a [[Sandbox.WebHome][Sandbox]] topic to try out the =+= and =+== options to experiment with ways to make macros easier to read.
<verbatim class="tml">
%SEARCH{"form.name ~ 'FAQForm'"
  type="query"
  web="System"
  nonoise="on"

  header+="|*Title*"
  format+="|$formfield(TopicTitle)"

  header+="|*Topic*"
  format+="|$web.$topic"

  header+="|*Summary*"
  format+="|$formfield(TopicSummary)"

  header+="|*Related Topics*"
  format+="|$formfield(RelatedTopics)"

  header+="|"
  format+="|"
}%</verbatim>

This gives:
%SEARCH{"form.name ~ 'FAQForm'"
  type="query"
  web="System"
  nonoise="on"

  header+="|*Title*"
  format+="|$formfield(TopicTitle)"

  header+="|*Topic*"
  format+="|$web.$topic"

  header+="|*Summary*"
  format+="|$formfield(TopicSummary)"

  header+="|*Related Topics*"
  format+="|$formfield(RelatedTopics)"

  header+="|"
  format+="|"
}%

%STOPINCLUDE%

---
*Related Topics:* MacrosQuickReference, PreferenceSettings, UserDocumentationCategory
