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

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)
// 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?

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

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

Thank you - this works.

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

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.

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

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

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.

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 :unamused:

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

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.

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

<?php

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

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

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