TemplateObject[expr]
represents a template object to be applied using functions like TemplateApply.
TemplateObject[form,args]
yields a TemplateObject with arguments, suitable for cloud deployment or other evaluation.
TemplateObject
TemplateObject[expr]
represents a template object to be applied using functions like TemplateApply.
TemplateObject[form,args]
yields a TemplateObject with arguments, suitable for cloud deployment or other evaluation.
Details and Options
- In TemplateObject[expr], the expression expr can contain the follow special elements:
-
TemplateSlot[name] a template slot to be filled when the template is applied TemplateExpression[expr] hold an expression until the template is applied TemplateIf[…] a conditional to evaluate when the template is applied TemplateSequence[…] a sequence to assemble when the template is applied TemplateWith[…] substitutions to make when the template is applied - TemplateObject is generated as the evaluated form of StringTemplate, FileTemplate, XMLTemplate, and NotebookTemplate.
- TemplateObject has the following options:
-
InsertionFunction Inherited function to apply before inserting expressions CombinerFunction Inherited function to apply to combine pieces before returning a result - TemplateObject can be nested, with different options for inner instances.
Examples
open all close allBasic Examples (1)
Using a TemplateObject:
t = {"This planet is", TemplateSlot["planet"]};
TemplateObject[t][<|"planet" -> "Mars"|>]Nest multiple instances of TemplateObject:
TemplateApply[{TemplateObject[{t, TemplateObject[t]}], TemplateObject[t]}, <|"planet" -> "Jupiter"|>]Scope (2)
TemplateObject can be used to make a template to create arbitrary expressions:
template = TemplateObject[{TemplateSlot["Color"], TemplateSlot["Shape"]}, CombinerFunction -> Graphics]Use TemplateApply to properly fill in the data and create a Graphics:
TemplateApply[template, <|"Color" -> Red, "Shape" -> Disk[]|>]Create a TemplateObject with bound data:
template = TemplateObject[Row[{"Hello ", TemplateSlot["Name"]}], <|"Name" -> "John"|>]Render the template without data:
TemplateApply[template]Options (2)
CombinerFunction (1)
Use a CombinerFunction to determine how a TemplateObject is combined:
TemplateApply[TemplateObject[{TemplateSlot["color"], TemplateSlot["shape"]}, CombinerFunction -> Graphics],
<|"shape" -> Disk[], "color" -> Red|>
]InsertionFunction (1)
Use an InsertionFunction to apply a function to all TemplateSlot instances:
TemplateApply[TemplateObject[{TemplateSlot["income2012"], TemplateSlot["income2013"]}, InsertionFunction -> Function[Style[#, If[Positive[#], Blue, Red]]] ],
<|"income2012" -> -100, "income2013" -> 300|>
]Applications (1)
Use TemplateExpression to hold an expression:
t = TemplateObject[TemplateExpression[
Plot[TemplateSlot["f"][x], {x, -4, 4}, PlotLabel -> TemplateSlot["f"]]]]Apply the TemplateObject to several functions:
Map[TemplateApply[t, <|"f" -> #|>]&, {Sin, Cos, Tan}]Properties & Relations (1)
Create a new TemplateObject:
t = TemplateObject[<|"today" -> TemplateSlot["today"]|>]Use TemplateApply to fill a TemplateSlot with a specific value:
TemplateApply[t, <|"today" -> Today|>]Neat Examples (1)
You can deploy a TemplateObject to the cloud. When you visit the URL, TemplateApply will render the template on each visit:
CloudDeploy[
XMLTemplate[
"now is: `Now`",
<|"Now" :> Now|>
]]See Also
TemplateApply FileTemplateApply StringTemplate FileTemplate XMLTemplate NotebookTemplate CreateNotebook
Function Repository: AssociationTemplate
Related Guides
Related Workflows
- Generate a Report According to a Schedule
History
Text
Wolfram Research (2014), TemplateObject, Wolfram Language function, https://reference.wolfram.com/language/ref/TemplateObject.html.
CMS
Wolfram Language. 2014. "TemplateObject." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TemplateObject.html.
APA
Wolfram Language. (2014). TemplateObject. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TemplateObject.html
BibTeX
@misc{reference.wolfram_2026_templateobject, author="Wolfram Research", title="{TemplateObject}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/TemplateObject.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_templateobject, organization={Wolfram Research}, title={TemplateObject}, year={2014}, url={https://reference.wolfram.com/language/ref/TemplateObject.html}, note=[Accessed: 12-June-2026]}