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.

DetailsDetails

  • 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
    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 . Named arguments corresponding to TemplateSlot["namei"] can be referred to using . TemplateExpression elements can be given as .

ExamplesExamplesopen allclose all

Basic Examples  (1)Basic Examples  (1)

Render a template:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Use key-value pairs:

In[3]:=
Click for copyable input
Out[3]=

TemplateApply works with any expression:

In[4]:=
Click for copyable input
Out[4]=
Introduced in 2014
(10.0)