alexanderjulo / kirby-twig

Twig Plugin for Kirby CMS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Twig Plugin for Kirby CMS

I don’t like Twig!

It’s okay, using this plugin is of course optional. You can keep using PHP templates in Kirby CMS.

I like Twig, but I don’t want to convert all my templates

Good news: you don’t have to! By default your PHP templates will keep working.

This plugin can work in two modes:

  1. Default: allow both Twig and PHP templates. (If both mytemplate.twig and mytemplate.php exist, the Twig template takes precedence.)
  2. Optional: allow Twig templates only.

Installation

You will need Composer, a command-line tool, to install this plugin.

  1. Download a copy of this repository and put it in your site/plugins folder. Rename the copied folder to twig.
  2. Open a terminal in your site/plugins/twig folder and run composer install.
  3. To activate the plugin, put c::set('plugin.twig.enabled', true); in your config.php.

You can now create .twig templates in your site/templates directory.

Options

// REQUIRED: activate Twig plugin
c::set('plugin.twig.enabled', true);

// Option: use Twig’s PHP cache in addition to Kirby’s HTML cache.
// (Only works when Kirby’s own cache is active.)
// Defaults to false
c::set('plugin.twig.cache', false);

// Option: disable or specify autoescaping type.
// http://twig.sensiolabs.org/doc/api.html#environment-options
// Defaults to true
c::set('plugin.twig.autoescape', true);

// Should we use .php templates as fallback when .twig
// templates don't exist? Set to false to only allow Twig templates.
// Defaults to true
c::set('plugin.twig.usephp', true);

Using Twig

See Twig templating tips for Kirby.

Known limitations

  1. Only a subset of Kirby’s functions and helpers are exposed to Twig templates (to be documented).

  2. Likewise, normal PHP functions are not available to Twig templates. If you want full PHP power, use PHP templates, or write Controllers that send data to your templates. Note that Twig already gives you a lot of tools for working with strings and arrays: Twig Reference.

  3. By design, Twig will not let you include files from outside the site/templates directory. If you have a use care where this is a problem, please open an issue.

About

Twig Plugin for Kirby CMS

License:MIT License


Languages

Language:PHP 100.0%