Tags:
create new tag
view all tags
---+ Parameterized Variables (Macros) %STARTINCLUDE% It is possible to pass parameters to TWiki variables. This is called a macro in a programming language. To define a parameterized variable, set a variable that contains other variables, such as: <verbatim> * Set EXAMPLE = Example variable using %DEFAULT%, %PARAM1% and %PARAM2% * Set DEMO = Demo using %DEFAULT{ default="(undefined)" }%, %PARAM1{ default="(undefined)" }% and %PARAM2{ default="(undefined)" }% </verbatim> A special =%<nop>DEFAULT%= variable denotes the default (nameless) parameter of the calling variable. Variables optionally may list a =default="..."= parameter that gets used in case the calling variable does not specify that parameter. To use a parameterized variable (or call a macro), add parameters within the curly brackets, such as: <verbatim> * %EXAMPLE{ "foo" PARAM1="bar" PARAM2="baz" }% * %DEMO{ "demo" PARAM2="parameter 2" }% -- note that PARAM1 is missing </verbatim> which resolves to: * %EXAMPLE{ "foo" PARAM1="bar" PARAM2="baz" }% * %DEMO{ "demo" PARAM2="parameter 2" }% -- note that PARAM1 is missing Parameters in the variable definition are expanded using the following sequence: 1. Parameter from variable call. In above example, =%<nop>PARAM1%= gets expanded to =bar=. 2. Session variable and preferences settings ---++!! Example *Define variables:* <verbatim> * Set DRINK = red wine * Set FAVORITE = My %DEFAULT{default="favorite"}% dish is %DISH{default="steak"}%, my %DEFAULT{default="favorite"}% drink is %DRINK%. </verbatim> %T% The default can be defined with a default parameter (=%<nop>DISH{default="steak"}%=), or as a preferences setting (=Set DRINK = ...=). *Use Variables:* <verbatim> %FAVORITE{ DISH="Sushi" DRINK="Sake" }% </verbatim> Returns: %BR% %FAVORITE{ DISH="Sushi" DRINK="Sake" }% <verbatim> %FAVORITE{}% </verbatim> Returns: %BR% %FAVORITE{}% <verbatim> %FAVORITE{ "preferred" }% </verbatim> Returns: %BR% %FAVORITE{ "preferred" }% %STOPINCLUDE% __Related:__ TWikiVariables, IncludeTopicsAndWebPages
E
dit
|
A
nexar
|
Watch
|
Im
p
rimir
|
H
istórico
: r1
|
We
b
|
V
er tópico
|
Ra
w
edit
|
M
ais ações de tópico
Versão do tópico: r1 - 27 Mar 2011
-
TWikiContributor
Home
Site map
Main web
Sandbox web
TWiki web
Web TWiki
User registration
Usuários
Grupos
Índice
Busca
Alterações
Notificações
Fonte RSS
Estatísticas
Preferências
P
Ver
Raw View
Print version
Find backlinks
History
More topic actions
Editar
Editar modo texto
Attach file or image
Editar preferências do tópico
Marcar novo tópico pai
More topic actions
Referência do usuário
ATasteOfTWiki
TextFormattingRules
TWikiVariables
FormattedSearch
QuerySearch
TWikiDocGraphics
TWikiSkinBrowser
InstalledPlugins
Manutenção Administrativa
Reference Manual
InterWikis
ManagingUsers
ManagingWebs
TWikiSiteTools
TWikiPreferences
WebPreferences
Categorias
Admin Documentation
Admin Tools
Developer Doc
User Documentation
User Tools
Account
Iniciar sessão
Български
Cesky
Dansk
Deutsch
English
Español
_Français_
Italiano
日本語
한글
Nederlands
Polski
Português
Русский
Svenska
简体中文
簡體中文
E
dit
A
nexar
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Idéias, solicitações, problemas com relação ao TWiki?
Nos dê um retorno
Note:
Please contribute updates to this topic on TWiki.org at
TWiki:TWiki.ParameterizedVariables
.