TemplateIf
✖
TemplateIf
✖
TemplateIf[condition,tclause]
represents an element of a template object that inserts tclause if the condition evaluates to True.
Details and Options

- condition can be either a TemplateSlot or TemplateExpression.
- The tclause is used when condition===True.
- If an fclause is not provided, the value Sequence[] is used instead.
- In an XML template, TemplateIf can be indicated using <wolfram:condition>...</wolfram:condition>. Multiple conditions can be nested using <wolfram:switch><wolfram:condition>...</wolfram:condition>...<wolfram:else>...</wolfram:else></wolfram:switch>.
- TemplateIf has the option InsertionFunction, with default setting Inherited, which specifies how the content of each template slot should be formatted before inserting it.
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
Using TemplateIf:
In[1]:=1

✖
https://wolfram.com/xid/0b8c13lbc9-xjdo5o
Out[1]=1

Run a test over a TemplateSlot:
In[2]:=2

✖
https://wolfram.com/xid/0b8c13lbc9-xdotqs
Out[2]=2

Options (1)Common values & functionality for each option
InsertionFunction (1)
Using an InsertionFunction:
In[1]:=1

✖
https://wolfram.com/xid/0b8c13lbc9-ri9lzm
Out[1]=1

InsertionFunction can be any function:
In[2]:=2

✖
https://wolfram.com/xid/0b8c13lbc9-uugai4
Out[2]=2

Wolfram Research (2014), TemplateIf, Wolfram Language function, https://reference.wolfram.com/language/ref/TemplateIf.html.
✖
Wolfram Research (2014), TemplateIf, Wolfram Language function, https://reference.wolfram.com/language/ref/TemplateIf.html.
Text
Wolfram Research (2014), TemplateIf, Wolfram Language function, https://reference.wolfram.com/language/ref/TemplateIf.html.
✖
Wolfram Research (2014), TemplateIf, Wolfram Language function, https://reference.wolfram.com/language/ref/TemplateIf.html.
CMS
Wolfram Language. 2014. "TemplateIf." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TemplateIf.html.
✖
Wolfram Language. 2014. "TemplateIf." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TemplateIf.html.
APA
Wolfram Language. (2014). TemplateIf. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TemplateIf.html
✖
Wolfram Language. (2014). TemplateIf. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TemplateIf.html
BibTeX
✖
@misc{reference.wolfram_2025_templateif, author="Wolfram Research", title="{TemplateIf}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/TemplateIf.html}", note=[Accessed: 06-June-2025
]}
BibLaTeX
✖
@online{reference.wolfram_2025_templateif, organization={Wolfram Research}, title={TemplateIf}, year={2014}, url={https://reference.wolfram.com/language/ref/TemplateIf.html}, note=[Accessed: 06-June-2025
]}