# snippet()

Embeds a snippet from the snippet folder

****

- Source: <https://github.com/getkirby/kirby/tree/5.5.3/config/helpers.php#L527>

****

```php
snippet($name, $data = [ ], bool $return = false, bool $slots = false): Kirby\Template\Snippet|string|null
```

## Parameters

| Name | Type | Default | Description |
| ---- | ---- | ---- | ---- |
| `$name` (required) | `mixed` | – | – |
| `$data` | `mixed` | `[ ]` | – |
| `$return` | `bool` | `false` | – |
| `$slots` | `bool` | `false` | – |

## Return types

`Kirby\Template\Snippet`, `string` or `null`

## Examples

```php
// Include the header snippet
<?php snippet('header') ?>

// Set the $class variable inside the snippet to "blog"
<?php snippet('header', ['class' => 'blog']) ?>

// Return the rendered snippet code
<?php $header = snippet('header', [], true); ?>
<?php $header = snippet('header', ['class' => 'blog'], true); ?>
```

## Snippet alternatives
You can define an array of snippet alternatives if the first snippet cannot be found:

```php
<?php snippet(['snippet1', 'snippet2', 'snippet3']) ?>
```

This is useful if you want to provide fallbacks for a snippet based on page input, in case the snippet does not exist:

```php
<?php snippet(['articles/' . $page->postType(), 'articles/default']) ?>
```