# Is it possible to use Kirby-Snippets outside of Kirby?

**URL:** <https://forum.getkirby.com/t/is-it-possible-to-use-kirby-snippets-outside-of-kirby/5656>\
**Category:** Questions\
**Tags:** v2\
**Created:** [November 3, 2016, 9:56am UTC](https://forum.getkirby.com/t/is-it-possible-to-use-kirby-snippets-outside-of-kirby/5656 "2016-11-03T09:56:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giannis](https://avatars.discourse-cdn.com/v4/letter/g/aca169/32.png) [@Giannis](https://forum.getkirby.com/u/Giannis)\
**Post date:** [November 3, 2016, 9:56am UTC](https://forum.getkirby.com/t/is-it-possible-to-use-kirby-snippets-outside-of-kirby/5656/1 "2016-11-03T09:56:35Z")

</div>

Hi, I’ve got a Kirby installation and PHP/MySQL-website. Is it possible to use Kirby-snippets as template-parts in my php-site?

I used allready a script (from [Kirby 2.0 sneak peek](https://getkirby.com/blog/sneak-peek))  
// load the bootstrapper  
require(‘kirby/bootstrap.php’);

```
// initialize the site for the first time
$site = site();

// load something from the API
$page = $site->pages()->find('my/awesome/page');

// do something with the page object
echo $page->title();

```

This works fine, even with snippets - but if I include my footer-snippet with “$site-\>copyright()” in it - it breaks down. What can I do?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [November 3, 2016, 10:36am UTC](https://forum.getkirby.com/t/is-it-possible-to-use-kirby-snippets-outside-of-kirby/5656/2 "2016-11-03T10:36:30Z")

</div>

If you pass the `$site` variable to the snippet, it should work:

```auto
snippet('footer', array('site' => $site));

```

---

<div class="post-metadata">

**Author:** ![Giannis](https://avatars.discourse-cdn.com/v4/letter/g/aca169/32.png) [@Giannis](https://forum.getkirby.com/u/Giannis)\
**Post date:** [November 3, 2016, 10:56am UTC](https://forum.getkirby.com/t/is-it-possible-to-use-kirby-snippets-outside-of-kirby/5656/3 "2016-11-03T10:56:04Z")

</div>

Thank you - this works.

Is it even possible to use $site-\>copyright()-\>kirbytext() or make the fingerprint-plugin for static-files work?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [November 3, 2016, 11:38am UTC](https://forum.getkirby.com/t/is-it-possible-to-use-kirby-snippets-outside-of-kirby/5656/4 "2016-11-03T11:38:48Z")

</div>

I think the field methods are not loaded with the bootstrap file, that’s why they don’t work in config.php either.

I just tested with launching Kirby after requiring the bootstrap file just as in index.php in a external file and that did do the job, but I’m not really sure if that’s really the way to do it.

```auto
require('kirby/bootstrap.php');
kirby()->launch();

```

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [November 3, 2016, 2:20pm UTC](https://forum.getkirby.com/t/is-it-possible-to-use-kirby-snippets-outside-of-kirby/5656/5 "2016-11-03T14:20:02Z")

</div>

To use the `$site->copyright()->kirbytext()` method, you need to load the so-called extension files:

```auto
kirby()->extensions();

```

before calling the snippet. Using `kirby()->launch()` will output the full page source of the “current page”, but if you only need the snippet, using it like this should work.

---

<div class="post-metadata">

**Author:** ![Giannis](https://avatars.discourse-cdn.com/v4/letter/g/aca169/32.png) [@Giannis](https://forum.getkirby.com/u/Giannis)\
**Post date:** [November 3, 2016, 4:08pm UTC](https://forum.getkirby.com/t/is-it-possible-to-use-kirby-snippets-outside-of-kirby/5656/6 "2016-11-03T16:08:38Z")

</div>

Hm, I tested your suggestions and in my case it doesn’t work as expected. This is the content of my test.php:

```
<?php
require('./kirby/bootstrap.php');
require('site.php');
kirby()->launch();
kirby()->extensions();
$site = site();

echo $site->copyright()->kirbytext();
echo snippet('footer', array('site' => $site))
?>

```

The $site-\>copyright()-\>kirbytext(); in this example works - but not, if it is in the snippet 😒

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [November 3, 2016, 4:23pm UTC](https://forum.getkirby.com/t/is-it-possible-to-use-kirby-snippets-outside-of-kirby/5656/7 "2016-11-03T16:23:43Z")

</div>

Hm, in my test it worked with `kirby()->launch()` only, not with `kirby()->extensions()`, but also in the snippet…

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [November 3, 2016, 4:30pm UTC](https://forum.getkirby.com/t/is-it-possible-to-use-kirby-snippets-outside-of-kirby/5656/8 "2016-11-03T16:30:42Z")

</div>

Well, either `launch` or `extensions`, if you use `launch` you don’t need `extensions`.

Strange that it doesn’t work in the snippet, it should work just the same. I’m currently not able to test this, but I will do some tests.

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [November 6, 2016, 11:00am UTC](https://forum.getkirby.com/t/is-it-possible-to-use-kirby-snippets-outside-of-kirby/5656/9 "2016-11-06T11:00:57Z")

</div>

The following code works for me, also in the snippet:

```auto
<?php

require('./kirby/bootstrap.php');
require('site.php');

$site = site();
kirby()->extensions();

echo $site->copyright()->kirbytext();
echo snippet('footer', array('site' => $site));

```

---

<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, 4:54pm UTC](https://forum.getkirby.com/t/is-it-possible-to-use-kirby-snippets-outside-of-kirby/5656/10 "2025-02-06T16:54:52Z")

</div>


