Working with Templates

The Wolfram Language has a powerful symbolic templating framework that can be used with strings, files, XML-like structures, notebooks, and other constructs.

Types of Templates

StringTemplate  ▪  FileTemplate  ▪  XMLTemplate  ▪  NotebookTemplate

TemplateObject general symbolic template

Symbolic Template Elements

TemplateSlot a slot to fill when the template is applied

TemplateExpression an arbitrary expression evaluated when the template is applied

TemplateWith a way to define local variables inside templates

TemplateIf a conditional to use when the template is applied

TemplateSequence specification of a sequence to assemble during template application

Text Transformation »

Pluralize pluralize a word if appropriate

Capitalize  ▪  TextString  ▪  StringRepeat  ▪  ...

LLM-Based Templates »

LLMFunction  ▪  LLMExampleFunction  ▪  LLMResourceFunction  ▪  LLMPrompt  ▪  ...

Template Syntax in Strings and Text Files

<* expr *> general template expression (TemplateExpression)

`` successive template slots (TemplateSlot[1], )

`i` numbered template slots

`name` named template slots (TemplateSlot["name"])

#, #i, #name template slots appearing inside <* *>

Template Tags for XML-Like Documents »

<wolfram:expr></wolfram:expr> tags for a template expression

<wolfram:slot> tag for a template slot

<wolfram:sequence> tag for a template sequence

  ▪    ▪    ▪  ...

Template Notebooks

File New Programmatic Notebook Template Notebook open a new template notebook

CreateNotebook programmatically open a blank template notebook

GenerateDocument generate a report by applying a template notebook to data

button to insert a slot to be filled from data when the template is applied

button to insert an expression to be evaluated when the template is applied

Applying Templates

TemplateApply apply a template, returning the expression generated

FileTemplateApply apply a template, putting the result in a file

GenerateDocument generate a report using a template