---
title: "TemplateSlot"
language: "en"
type: "Symbol"
summary: "TemplateSlot[n] represents a template slot to be filled from the n\\[Null]^th argument when the template is applied. TemplateSlot[name] represents a template slot to be filled from an element with key name in an association appearing in the first argument."
keywords: 
- template slot
- template argument
- template insertion
canonical_url: "https://reference.wolfram.com/language/ref/TemplateSlot.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Working with Templates"
    link: "https://reference.wolfram.com/language/guide/WorkingWithTemplates.en.md"
  - 
    title: "XML Templates"
    link: "https://reference.wolfram.com/language/guide/XMLTemplates.en.md"
  - 
    title: "Form Structure & Layout"
    link: "https://reference.wolfram.com/language/guide/FormStructureAndLayout.en.md"
  - 
    title: "String Manipulation"
    link: "https://reference.wolfram.com/language/guide/StringManipulation.en.md"
related_workflows: 
  - 
    title: "Generate a Report According to a Schedule"
    link: "https://reference.wolfram.com/language/workflow/GenerateAReportAccordingToASchedule.en.md"
related_functions: 
  - 
    title: "TemplateExpression"
    link: "https://reference.wolfram.com/language/ref/TemplateExpression.en.md"
  - 
    title: "TemplateApply"
    link: "https://reference.wolfram.com/language/ref/TemplateApply.en.md"
  - 
    title: "Slot"
    link: "https://reference.wolfram.com/language/ref/Slot.en.md"
  - 
    title: "TemplateObject"
    link: "https://reference.wolfram.com/language/ref/TemplateObject.en.md"
  - 
    title: "StringTemplate"
    link: "https://reference.wolfram.com/language/ref/StringTemplate.en.md"
  - 
    title: "FileTemplate"
    link: "https://reference.wolfram.com/language/ref/FileTemplate.en.md"
  - 
    title: "XMLTemplate"
    link: "https://reference.wolfram.com/language/ref/XMLTemplate.en.md"
---
# TemplateSlot

TemplateSlot[n] represents a template slot to be filled from the n$$^{\text{th}}$$ argument when the template is applied.

TemplateSlot[name] represents a template slot to be filled from an element with key name in an association appearing in the first argument.

## Details and Options

* In a string template given as a string, or in a file template, successive `````` indicate ``TemplateSlot[i]`` for successive ``i``.

* The form ```n``` for integer ``n`` corresponds to ``TemplateSlot[n]``. This is analogous to the form ``#n`` for ``Slot``.

* The form ```name``` for an alphanumeric string ``name`` not beginning with digits corresponds to ``TemplateSlot[1, "name"]``. This is analogous to ``#name`` for ``Slot``.

* Within `` <  * … *  > `` in a string template given as a string, any ``#p…`` that appear are effectively interpreted as ``TemplateSlot[p, …]``.

* In an ``XMLTemplate``, ``TemplateSlot`` can be indicated using ``<wolfram:slot>`` ... ``</wolfram:slot>``.

* ``TemplateSlot`` supports the following options:

|                    |           |                                   |
| ------------------ | --------- | --------------------------------- |
| InsertionFunction  | Inherited | how the value should be formatted |
| DefaultValue       | Missing   | the default value to use          |

---

## Examples (3)

### Basic Examples (1)

Using a ``TemplateSlot`` :

```wl
In[1]:=
t = Mean[{TemplateSlot["me"], 50, 30}];
TemplateApply[t, <|"me" -> 100|>]

Out[1]= 60
```

Using ``TemplateSlot`` in a ``TemplateIf`` to handle plurals:

```wl
In[2]:=
t = TemplateIf[
	Length[TemplateSlot["planets"]] === 1, 
	{"There is one planet"}, 
	{"There are many planets"}
	];
TemplateApply[t, <|"planets"  -> {"Mars", "Earth", "Jupiter"}|>]

Out[2]= {"There are many planets"}
```

### Options (2)

#### InsertionFunction (1)

Use ``InsertionFunction`` to change the ``Slot`` behavior:

```wl
In[1]:=
t = TemplateSlot["data", InsertionFunction -> Total];
TemplateApply[t, <|"data" -> Range[10]|>]

Out[1]= 55
```

The ``InsertionFunction`` ignores the ``Inherited`` function:

```wl
In[2]:=
TemplateApply[
	TemplateObject[TemplateSlot["data"], InsertionFunction -> ToString], 
	<|"data" -> Range[10]|>
	]

Out[2]= "{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}"
```

#### DefaultValue (1)

Use a default value:

```wl
In[1]:=
t = TemplateSlot[1, DefaultValue -> "No data found"];
TemplateApply[{"Data is:", t}]

Out[1]= {"Data is:", "No data found"}
```

## See Also

* [`TemplateExpression`](https://reference.wolfram.com/language/ref/TemplateExpression.en.md)
* [`TemplateApply`](https://reference.wolfram.com/language/ref/TemplateApply.en.md)
* [`Slot`](https://reference.wolfram.com/language/ref/Slot.en.md)
* [`TemplateObject`](https://reference.wolfram.com/language/ref/TemplateObject.en.md)
* [`StringTemplate`](https://reference.wolfram.com/language/ref/StringTemplate.en.md)
* [`FileTemplate`](https://reference.wolfram.com/language/ref/FileTemplate.en.md)
* [`XMLTemplate`](https://reference.wolfram.com/language/ref/XMLTemplate.en.md)

## Related Guides

* [Working with Templates](https://reference.wolfram.com/language/guide/WorkingWithTemplates.en.md)
* [XML Templates](https://reference.wolfram.com/language/guide/XMLTemplates.en.md)
* [Form Structure & Layout](https://reference.wolfram.com/language/guide/FormStructureAndLayout.en.md)
* [String Manipulation](https://reference.wolfram.com/language/guide/StringManipulation.en.md)

## Related Workflows

* [Generate a Report According to a Schedule](https://reference.wolfram.com/language/workflow/GenerateAReportAccordingToASchedule.en.md)

## History

* [Introduced in 2014 (10.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn100.en.md)