StringTemplate
✖
StringTemplate
yields a TemplateObject expression that represents a string template to be applied to arguments.
yields a TemplateObject with arguments, suitable for cloud deployment or other evaluation.
Details and Options

- The following special forms can be used inside the string:
-
`` TemplateSlot[n], for n taking successive values 1, 2, 3, … `n` TemplateSlot[n] `name` TemplateSlot["name"] <*expr*> TemplateExpression[expr] - A StringTemplate object can be rendered using TemplateApply[StringTemplate[…],{e1,e2,…}] or using the form StringTemplate[…][e1,e2,…].
- StringTemplate has the following options:
-
CombinerFunction StringJoin function to apply to combine pieces before returning a result InsertionFunction TextString function or format to apply before inserting expressions - In StringTemplate[File[…]] and StringTemplate[URL[…]], the content of the source file etc. is imported as a string.
Examples
open allclose allBasic Examples (4)Summary of the most common use cases
Apply a string template with slots named a and b:

https://wolfram.com/xid/0b8b4n13y6-k0x3ot

An equivalent form using TemplateApply:

https://wolfram.com/xid/0b8b4n13y6-40pa4f

The StringTemplate is not needed inside TemplateApply:

https://wolfram.com/xid/0b8b4n13y6-php541

Apply a string template to positional arguments:

https://wolfram.com/xid/0b8b4n13y6-gyq9xj


https://wolfram.com/xid/0b8b4n13y6-ghm5da

The expression inside <* ... *> is evaluated when the string template is applied:

https://wolfram.com/xid/0b8b4n13y6-9c9jtf

Include a template slot as well as an expression in the template string:

https://wolfram.com/xid/0b8b4n13y6-bfe2m0

Values from the association can be used in the template expression:

https://wolfram.com/xid/0b8b4n13y6-c0kvbh

Rule delayed can be used to delay computations:

https://wolfram.com/xid/0b8b4n13y6-rccdyo


https://wolfram.com/xid/0b8b4n13y6-igiw7l

Expressions are spliced into the string using TextString:

https://wolfram.com/xid/0b8b4n13y6-gzfpvt

Scope (4)Survey of the scope of standard use cases
File is fully supported:

https://wolfram.com/xid/0b8b4n13y6-f48c8p

Templates can be hosted in the Wolfram Cloud:

https://wolfram.com/xid/0b8b4n13y6-zn99tp

CloudObject can be directly used by TemplateApply:

https://wolfram.com/xid/0b8b4n13y6-euzfet

The second argument of StringTemplate can be used to bound data to the template:

https://wolfram.com/xid/0b8b4n13y6-u7p483


https://wolfram.com/xid/0b8b4n13y6-8tx9dm

URL can be used to fetch templates:

https://wolfram.com/xid/0b8b4n13y6-ehr44g


https://wolfram.com/xid/0b8b4n13y6-uwsajo


https://wolfram.com/xid/0b8b4n13y6-se9tn7

Options (2)Common values & functionality for each option
CombinerFunction (1)
Specify a different way to combine parts of templates:

https://wolfram.com/xid/0b8b4n13y6-mvn9kj

It can be used to return any expression, not only a string:

https://wolfram.com/xid/0b8b4n13y6-4xbpcu


https://wolfram.com/xid/0b8b4n13y6-yh0ga7

Properties & Relations (3)Properties of the function, and connections to other functions
StringTemplate evaluates to a TemplateObject:

https://wolfram.com/xid/0b8b4n13y6-zib0jp

If you deploy a template with data, each time you visit it TemplateApply will render the content again:

https://wolfram.com/xid/0b8b4n13y6-kwsq8a

TemplateApply can be used to parse and apply a string template in one step:

https://wolfram.com/xid/0b8b4n13y6-8qyixc

Possible Issues (1)Common pitfalls and unexpected behavior
Data in the second argument of StringTemplate takes precedence over arguments in TemplateApply:

https://wolfram.com/xid/0b8b4n13y6-4hpk4b

Neat Examples (1)Surprising or curious use cases
You can deploy a StringTemplate to the cloud. When you visit the URL, TemplateApply will render the template on each visit:

https://wolfram.com/xid/0b8b4n13y6-j836et

Wolfram Research (2014), StringTemplate, Wolfram Language function, https://reference.wolfram.com/language/ref/StringTemplate.html.
Text
Wolfram Research (2014), StringTemplate, Wolfram Language function, https://reference.wolfram.com/language/ref/StringTemplate.html.
Wolfram Research (2014), StringTemplate, Wolfram Language function, https://reference.wolfram.com/language/ref/StringTemplate.html.
CMS
Wolfram Language. 2014. "StringTemplate." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/StringTemplate.html.
Wolfram Language. 2014. "StringTemplate." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/StringTemplate.html.
APA
Wolfram Language. (2014). StringTemplate. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/StringTemplate.html
Wolfram Language. (2014). StringTemplate. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/StringTemplate.html
BibTeX
@misc{reference.wolfram_2025_stringtemplate, author="Wolfram Research", title="{StringTemplate}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/StringTemplate.html}", note=[Accessed: 11-May-2025
]}
BibLaTeX
@online{reference.wolfram_2025_stringtemplate, organization={Wolfram Research}, title={StringTemplate}, year={2014}, url={https://reference.wolfram.com/language/ref/StringTemplate.html}, note=[Accessed: 11-May-2025
]}