TemplateExpression
TemplateExpression[expr]
represents an expression held until a template is applied, and then evaluated.
Details and Options
- TemplateExpression has attribute HoldFirst.
- TemplateExpression normally appears inside TemplateObject. It can be generated by StringTemplate, FileTemplate, XMLTemplate, and NotebookTemplate.
- When a template is applied, TemplateExpression[expr] is effectively replaced with the result of evaluating ifunc[expr], where ifunc is value of the option InsertionFunction, which may be specified directly or inherited from other template constructs.
- The default value of the option InsertionFunction is Inherited, which specifies that the value of InsertionFunction should be taken from the enclosing template construct, typically a TemplateObject. If unspecified, Identity will be used, which means the expr will be evaluated and then inserted unchanged.
- In TemplateExpression[expr], the values of any TemplateSlot expressions that occur in expr are inserted before expr is evaluated. These values are not affected by the setting of InsertionFunction.
- In a string template given as a string, TemplateExpression[expr] can be indicated as <*expr*>.
- In a file template, TemplateExpression[expr] can appear in the file as <*expr*>.
- Within <*…*>, any #p… that appear are effectively interpreted as TemplateSlot[p,…].
- In an XML template, TemplateExpression[expr] can appear as <wolfram:expr> expr </wolfram:expr>.
- In a notebook template, a TemplateExpression can typically be inserted using the button.
Examples
open allclose allOptions (1)
InsertionFunction (1)
Use InsertionFunction to specify a function to apply before the TemplateExpression is inserted:
The default value of Inherited causes the InsertionFunction to be inherited from any containing template constructs:
Specifying an InsertionFunction for the TemplateExpression overrides the value inherited from other constructs:
Properties & Relations (1)
Functions like StringTemplate generate a TemplateObject that specifies an appropriate InsertionFunction. This InsertionFunction is then inherited by constructs such as TemplateExpression:
TemplateExpression[expr] will not evaluate expr before inserting the result into the template, independent of whether evaluation would normally occur in that part of the result:
Text
Wolfram Research (2014), TemplateExpression, Wolfram Language function, https://reference.wolfram.com/language/ref/TemplateExpression.html.
CMS
Wolfram Language. 2014. "TemplateExpression." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TemplateExpression.html.
APA
Wolfram Language. (2014). TemplateExpression. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TemplateExpression.html