WOLFRAM

TemplateApply[template]

applies a template, evaluating all template elements it contains.

TemplateApply[template,args]

applies a template, using args to fill slots in the template.

Details and Options

  • The template in TemplateApply can be an explicit TemplateObject, as generated from StringTemplate, FileTemplate, XMLTemplate, or NotebookTemplate.
  • The following special forms can also be used directly as templates:
  • "string"string template
    File["filename.xx"]general file template
    File["filename.html"] etc.XML-like file template
    File["filename.nb"] etc.notebook-like file template
    URL[]a URL pointing to a file template
    NotebookObject[]notebook template
    CloudObject[]template type based on the contents of the cloud object
  • In TemplateApply[template,args], args can have the following forms:
  • {arg1,arg2,}positional arguments
    <|"name1"->val1,"name2"->val2,|>named arguments
  • In string and general file templates, positional arguments corresponding to TemplateSlot[i] can be referred to using `` and `i`. Named arguments corresponding to TemplateSlot["namei"] can be referred to using `namei`. TemplateExpression elements can be given as <**>.

Examples

open allclose all

Basic Examples  (3)Summary of the most common use cases

Render a template:

Out[1]=1
Out[2]=2

Use key-value pairs:

Out[3]=3

TemplateApply works with any expression:

Out[1]=1

TemplateApply can be used directly on strings; in that case, the string is taken to be a StringTemplate:

Out[2]=2

TemplateApply can be used to build held expressions:

Out[1]=1
Out[2]=2

Scope  (5)Survey of the scope of standard use cases

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

Out[1]=1

File is fully supported:

Out[1]=1

Templates can be hosted in the Wolfram Cloud:

Out[1]=1

CloudObject can be directly used by TemplateApply:

Out[2]=2

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

Out[1]=1
Out[2]=2

URL can be used to fetch templates:

Out[1]=1
Out[2]=2
Out[3]=3

URL can be directly used by TemplateApply:

Out[4]=4

Generalizations & Extensions  (2)Generalized and extended use cases

CombinerFunction  (1)

Specify a different way to combine parts of templates:

Using CombinerFunction:

Out[1]=1

InsertionFunction  (1)

Specify a function to convert arguments before they are inserted:

Applications  (1)Sample problems that can be solved with this function

TemplateApply can be used to build complex expressions:

Out[1]=1
Out[2]=2

Properties & Relations  (1)Properties of the function, and connections to other functions

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

Out[6]=6

Neat Examples  (1)Surprising or curious use cases

You can deploy any TemplateObject to the cloud. When you visit the URL, TemplateApply will render the template on each visit:

Out[1]=1
Wolfram Research (2014), TemplateApply, Wolfram Language function, https://reference.wolfram.com/language/ref/TemplateApply.html (updated 2016).
Wolfram Research (2014), TemplateApply, Wolfram Language function, https://reference.wolfram.com/language/ref/TemplateApply.html (updated 2016).

Text

Wolfram Research (2014), TemplateApply, Wolfram Language function, https://reference.wolfram.com/language/ref/TemplateApply.html (updated 2016).

Wolfram Research (2014), TemplateApply, Wolfram Language function, https://reference.wolfram.com/language/ref/TemplateApply.html (updated 2016).

CMS

Wolfram Language. 2014. "TemplateApply." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/TemplateApply.html.

Wolfram Language. 2014. "TemplateApply." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/TemplateApply.html.

APA

Wolfram Language. (2014). TemplateApply. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TemplateApply.html

Wolfram Language. (2014). TemplateApply. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TemplateApply.html

BibTeX

@misc{reference.wolfram_2025_templateapply, author="Wolfram Research", title="{TemplateApply}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/TemplateApply.html}", note=[Accessed: 25-March-2025 ]}

@misc{reference.wolfram_2025_templateapply, author="Wolfram Research", title="{TemplateApply}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/TemplateApply.html}", note=[Accessed: 25-March-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_templateapply, organization={Wolfram Research}, title={TemplateApply}, year={2016}, url={https://reference.wolfram.com/language/ref/TemplateApply.html}, note=[Accessed: 25-March-2025 ]}

@online{reference.wolfram_2025_templateapply, organization={Wolfram Research}, title={TemplateApply}, year={2016}, url={https://reference.wolfram.com/language/ref/TemplateApply.html}, note=[Accessed: 25-March-2025 ]}