TemplateWith["name"value,expr]
represents an element of a template object that evaluates expr after replacing TemplateSlot["name"] with value.
TemplateWith[{"name1"value1,"name2"value2, …},expr]
evaluates expr with a list of key-value pairs.
TemplateWith
TemplateWith["name"value,expr]
represents an element of a template object that evaluates expr after replacing TemplateSlot["name"] with value.
TemplateWith[{"name1"value1,"name2"value2, …},expr]
evaluates expr with a list of key-value pairs.
Details
- TemplateWith allows you to define local constants inside a TemplateObject.
- In an XMLTemplate, TemplateWith can be indicated using <wolfram:with var1="..." var2="...">...</wolfram:with>.
Examples
open all close allBasic Examples (1)
Using TemplateSlot:
t = TemplateWith[
"fib" -> Fibonacci[TemplateSlot["number"]], {"My favorite Fibonacci number is:", TemplateSlot["fib"]}
];
TemplateApply[t, <|"number" -> 15|>]t = TemplateWith[
{"planet" -> "Mars", "color" -> "Red"}, {"This is planet ", TemplateSlot["planet"], ", with a nice ", TemplateSlot["color"], " color."}
];
TemplateApply[t] // StringJoinScope (1)
Hold evaluation with TemplateExpression:
t = TemplateWith[
"plot" -> TemplateExpression[
Plot[TemplateSlot["offset"] + Sin[x], {x, 0, 6Pi}]
],
{"Plot:", TemplateSlot["plot"]}
];
TemplateApply[t, <|"offset" -> 1|>]Use TemplateWith to transform TemplateSlot data:
t = TemplateWith[
"plot" -> TemplateExpression @ ArrayPlot[
TemplateSlot["data"],
ColorRules -> {1 -> Pink, 0 -> Yellow}
],
{"Data:", TemplateSlot["data"], "Plot:", TemplateSlot["plot"]}
];
TemplateApply[t, <|"data" -> {{1, 0, 0.3}, {1, 1, 0.3}, {0, 1, 0.7}}|>]See Also
Related Guides
History
Text
Wolfram Research (2014), TemplateWith, Wolfram Language function, https://reference.wolfram.com/language/ref/TemplateWith.html.
CMS
Wolfram Language. 2014. "TemplateWith." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TemplateWith.html.
APA
Wolfram Language. (2014). TemplateWith. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TemplateWith.html
BibTeX
@misc{reference.wolfram_2026_templatewith, author="Wolfram Research", title="{TemplateWith}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/TemplateWith.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_templatewith, organization={Wolfram Research}, title={TemplateWith}, year={2014}, url={https://reference.wolfram.com/language/ref/TemplateWith.html}, note=[Accessed: 13-June-2026]}