# Include snippets in Kirbytext using a Kirbytext filter

**URL:** <https://forum.getkirby.com/t/include-snippets-in-kirbytext-using-a-kirbytext-filter/3262>\
**Category:** Solutions\
**Tags:** v2\
**Created:** [February 7, 2016, 5:37pm UTC](https://forum.getkirby.com/t/include-snippets-in-kirbytext-using-a-kirbytext-filter/3262 "2016-02-07T17:37:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jensfranke](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jensfranke/32/722_2.png) [@jensfranke](https://forum.getkirby.com/u/jensfranke)\
**Post date:** [February 7, 2016, 5:37pm UTC](https://forum.getkirby.com/t/include-snippets-in-kirbytext-using-a-kirbytext-filter/3262/1 "2016-02-07T17:37:53Z")

</div>

I had some issues with using snippets inside of a custom Kirbytag because of the order how Kirby [parse](https://github.com/getkirby/kirby/blob/master/core/kirbytext.php#L41) content.

With the help of @lukasbestle I found a good solution with a custom [Post Filter](https://getkirby.com/docs/advanced/kirbytext#kirbytext-filters) instead of a custom Kirbytag:

```auto
<? kirbytext::$post[] = function($kirbytext, $text) {

    // searching for fields with the name mytag and 1 parameter for the uid of the module, example: (mytag:my-module)
    $text = preg_replace_callback('!\(mytag:(.*?)\)!is', function($matches) use($kirbytext) {

    $searchkey = trim($matches[1]);

    // $kirbytext has a reference to the field and the field has a reference to the page
    $module = $kirbytext->field->page->children()->findBy('uid', $searchkey);

    $html = snippet('components/mymodule', array('title' => $module->title(), 'text' => $module->text()->kirbytext()), true);

    return $html;

    }, $text);

  return $text;
};

```

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:00pm UTC](https://forum.getkirby.com/t/include-snippets-in-kirbytext-using-a-kirbytext-filter/3262/2 "2025-02-06T17:00:16Z")

</div>

Archived on February 6, 2025, 5:00pm UTC


