TemplateSlot[n]
represents a template slot to be filled from the n
argument when the template is applied.
TemplateSlot[name]
represents a template slot to be filled from an element with key name in an association appearing in the first argument.
TemplateSlot
TemplateSlot[n]
represents a template slot to be filled from the n
argument when the template is applied.
TemplateSlot[name]
represents a template slot to be filled from an element with key name in an association appearing in the first argument.
Details and Options
- In a string template given as a string, or in a file template, successive `` indicate TemplateSlot[i] for successive i.
- The form `n` for integer n corresponds to TemplateSlot[n]. This is analogous to the form #n for Slot.
- The form `name` for an alphanumeric string name not beginning with digits corresponds to TemplateSlot[1,"name"]. This is analogous to #name for Slot.
- Within <*…*> in a string template given as a string, any #p… that appear are effectively interpreted as TemplateSlot[p,…].
- In an XMLTemplate, TemplateSlot can be indicated using <wolfram:slot> ... </wolfram:slot>.
- TemplateSlot supports the following options:
-
InsertionFunction Inherited how the value should be formatted "DefaultValue" Missing the default value to use
Examples
open all close allBasic Examples (1)
Using a TemplateSlot:
t = Mean[{TemplateSlot["me"], 50, 30}];
TemplateApply[t, <|"me" -> 100|>]Using TemplateSlot in a TemplateIf to handle plurals:
t = TemplateIf[
Length[TemplateSlot["planets"]] === 1,
{"There is one planet"},
{"There are many planets"}
];
TemplateApply[t, <|"planets" -> {"Mars", "Earth", "Jupiter"}|>]Scope (2)
The first argument of TemplateSlot can be a number; it returns the first argument:
TemplateApply[TemplateSlot[1], {1}]TemplateApply automatically adds a list to any input that is not a List:
TemplateApply[TemplateSlot[1], <|"age" -> 32|>]The first argument of TemplateSlot can be a string; it returns the first named slot with that name:
TemplateApply[TemplateSlot["age"], <|"age" -> 32|>]If multiple associations are provided, the first available key from all associations will be used:
TemplateApply[TemplateSlot["name"], {<|"age" -> 32|>, <|"name" -> "Paul"|>}]Options (2)
InsertionFunction (1)
Use InsertionFunction to change the Slot behavior:
t = TemplateSlot["data", InsertionFunction -> Total];
TemplateApply[t, <|"data" -> Range[10]|>]The InsertionFunction ignores the Inherited function:
TemplateApply[
TemplateObject[TemplateSlot["data"], InsertionFunction -> ToString],
<|"data" -> Range[10]|>
]See Also
TemplateExpression TemplateApply Slot TemplateObject StringTemplate FileTemplate XMLTemplate
Function Repository: AssociationTemplate
Related Guides
Related Workflows
- Generate a Report According to a Schedule
History
Text
Wolfram Research (2014), TemplateSlot, Wolfram Language function, https://reference.wolfram.com/language/ref/TemplateSlot.html.
CMS
Wolfram Language. 2014. "TemplateSlot." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TemplateSlot.html.
APA
Wolfram Language. (2014). TemplateSlot. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TemplateSlot.html
BibTeX
@misc{reference.wolfram_2026_templateslot, author="Wolfram Research", title="{TemplateSlot}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/TemplateSlot.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_templateslot, organization={Wolfram Research}, title={TemplateSlot}, year={2014}, url={https://reference.wolfram.com/language/ref/TemplateSlot.html}, note=[Accessed: 13-June-2026]}