Kirby 3 Plugin Handlebars

site/controllers/handlebars.php

<?php
return function (Kirby\Cms\Site $site, Kirby\Cms\Page $page, Kirby\Cms\App $kirby) {
  return ['c'=>'Cassia', 'g'=>null];
};

site/template/render-unto.hbs

Render unto {{ c }} the things that are {{ c }}'s, and unto {{ g }} the things that are {{ g }}'s.

site/templates/handlebars.php

<?php
/** @var Kirby\Cms\App $kirby */
/** @var Kirby\Cms\Site $site */
/** @var Kirby\Cms\Page $page */
?><!DOCTYPE html>
<html <?= site()->attrLang() ?>>

  <head><?php snippet('plugin-htmlhead') ?></head>

  <body>
    <?php
      $github = lapse(md5($page->id()), function() {
        $m = 'https://raw.githubusercontent.com/bnomei/kirby3-plugins.bnomei.com/master/site/';
        return [
          'templates/handlebars' => html(Kirby\Http\Remote::get($m.'templates/handlebars.php')->content()),
          'templates/render-unto' => html(Kirby\Http\Remote::get($m.'templates/render-unto.hbs')->content()),
          'controllers/handlebars' => html(Kirby\Http\Remote::get($m.'controllers/handlebars.php')->content()),
        ];
    }); ?>

    <h1><?= $page->title()->html() ?></h1>

    <h2>site/controllers/handlebars.php</h2>
    <pre><code data-language="php"><?= $github['controllers/handlebars'] ?></code></pre>

    <h2>site/template/render-unto.hbs</h2>
    <pre><code data-language="php"><?= $github['templates/render-unto'] ?></code></pre>

    <h2>site/templates/handlebars.php</h2>
    <pre><code data-language="php"><?= $github['templates/handlebars'] ?></code></pre>

    <h2>pageMethod</h2>
    <blockquote><?php
      // template 'render-unto'
      // data from site/controllers/home.php merged with custom array
      echo $page->handlebars('render-unto', ['g'=>'Gods']); ?>
    </blockquote>

    <h2>hbs helper</h2>
    <blockquote>
      <?php hbs('render-unto', ['c' => 'Caesar', 'g' => 'God']) ?>
    </blockquote>

    <?php snippet('footer') ?>
  </body>
</html>

pageMethod

Render unto Cassia the things that are Cassia's, and unto Gods the things that are Gods's.

hbs helper

Render unto Caesar the things that are Caesar's, and unto God the things that are God's.