---
id: fast-element.when
title: when() function
hide_title: true
---
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[@microsoft/fast-element](./fast-element.md) &gt; [when](./fast-element.when.md)

## when() function

A directive that enables basic conditional rendering in a template.

<b>Signature:</b>

```typescript
export declare function when<TSource = any, TReturn = any>(binding: Binding<TSource, TReturn>, templateOrTemplateBinding: SyntheticViewTemplate | Binding<TSource, SyntheticViewTemplate>): CaptureType<TSource>;
```

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  binding | [Binding](./fast-element.binding.md)<!-- -->&lt;TSource, TReturn&gt; | The condition to test for rendering. |
|  templateOrTemplateBinding | [SyntheticViewTemplate](./fast-element.syntheticviewtemplate.md) \| [Binding](./fast-element.binding.md)<!-- -->&lt;TSource, [SyntheticViewTemplate](./fast-element.syntheticviewtemplate.md)<!-- -->&gt; | The template or a binding that gets the template to render when the condition is true. |

<b>Returns:</b>

[CaptureType](./fast-element.capturetype.md)<!-- -->&lt;TSource&gt;
