Plugin Kirby PHP Mustache

Example Usage

site/config/config.php

c::set('plugin.mustache.helpers.page', true);
// $page object in mustache
// will merge $page->content()->toArray() with additional data

site/templates/example.mustache

<div class="c-example">
  <header class="c-example__title"><h1>{{ page.title }}</h1></header>
  <div class="c-example__text">{{ page.text }}</div>
</div>

content/example/example.txt

Title: Templating
----
Text: is so much fun

site/templates/example.php

  c::set('plugin.mustache.helpers.page', true);
  echo $page->mustache(); // or...
  // mustache('example', $page->content()->toArray());

html output

<div class="c-example">
  <header class="c-example__title"><h1>Templating</h1></header>
  <div class="c-example__text">is so much fun</div>
</div>

More Awesomeness

  • Global helper function
  • Kirby Tag
  • Preview templates with dummy data using build-in dump
  • Change Paths
  • Bring in your own data not just Page Objects
  • Using Mustache Partials you can do Atomic Design as well
  • oh… and its free.
1 Like

It’s probably a great plugin… but I try to understand why a template language is needed. To me PHP is a template language.

What is the benefit of a template engine on top?

1 Like

certainly creating html template code can be done in plain php. but…

simple
mustache is imho as simple as a templating language can get without just being string replacement. being forced to create logicless templates really helps to apply MVC.

versatile
mustache templates can be parsed by more that one programming language. more than 40. thats great for modern ui design systems or if you have to use one.

atomic design
using partials nesting templates can be used for basic atomic design.

mustache
it has a {{ mustache }} just like me. :bearded_person:

1 Like

At least if you were forced to use a template language like this, you’d hopefully not come up with something like this :scream:.

Lol that made me laugh a lot. Yes… spare a thought for me on this cold Friday evening working with that nonsense. At least i have beer. :slight_smile:

Just my opinion but i think it probably makes more sense to use Blade, which there is already a solution for.

Well, freedom of choice is always nice to have, even if it means using none of these plugins.

Cheers, :beers::beers:

1 Like

Bottoms up!

Of course! I love a new Kirby plugin :slight_smile:

1 Like

@bnomei Don’t get me wrong, I didn’t mean to sound ungracious. Your efforts are appreciated. I will try your plugin. :peace_symbol:

1 Like

And I love a lively community no matter if I have (immediate) use for a plugin or not. And it’s food for our newsletter :corn::carrot::potato: Thanks for sharing, @bnomei.

1 Like

it is an awesome newsletter, love it when it hits my inbox. :sunny:

no worries. like with most of my plugins i take the extra mile to share them just to force myself to write better code.

1 Like

i had to work with an existing collection of mustache templates. not creating them myself. so using blade was never an option at all. could happen to others. thats why i shared the plugin.