snippet()
Embeds a snippet from the snippet folder
snippet(string|array $name, array|object $data = [ ], bool $return = false): string|nullParameters
| Name | Type | Default | 
|---|---|---|
| $name * | string|array | – | 
| $data | array|object | [ ] | 
| $return | bool | false | 
Return type
string|null
Example
// 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 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 snippet(['articles/' . $page->postType(), 'articles/default']) ?>