TemplateApply

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)

Render a template:

Use key-value pairs:

TemplateApply works with any expression:

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

TemplateApply can be used to build held expressions:

Scope  (5)

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

File is fully supported:

Templates can be hosted in the Wolfram Cloud:

CloudObject can be directly used by TemplateApply:

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

URL can be used to fetch templates:

URL can be directly used by TemplateApply:

Generalizations & Extensions  (2)

CombinerFunction  (1)

Specify a different way to combine parts of templates:

Using CombinerFunction:

InsertionFunction  (1)

Specify a function to convert arguments before they are inserted:

Applications  (1)

TemplateApply can be used to build complex expressions:

Properties & Relations  (1)

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

Neat Examples  (1)

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

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).

CMS

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

BibTeX

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

BibLaTeX

@online{reference.wolfram_2024_templateapply, organization={Wolfram Research}, title={TemplateApply}, year={2016}, url={https://reference.wolfram.com/language/ref/TemplateApply.html}, note=[Accessed: 08-December-2024 ]}