Download the PHP package fvsch/kirby-twig without Composer
On this page you can find all versions of the php package fvsch/kirby-twig. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fvsch/kirby-twig
More information about fvsch/kirby-twig
Files in fvsch/kirby-twig
Package kirby-twig
Short Description Twig templating support for Kirby CMS
License MIT
Homepage https://github.com/fvsch/kirby-twig/
Informations about the package kirby-twig
Twig Plugin for Kirby CMS
- Adds support for Twig templates to Kirby CMS 2.x.
- PHP templates still work, you don’t have to rewrite them if you don’t want to.
What it looks like
Before:
After:
Installation
Standard installation
- Download the latest release.
- Unzip, rename the
kirby-twig-main
folder to justtwig
and put it in your project’ssite/plugins
folder.
You should end up with a folder structure like this:
Using Composer
Require fvsch/kirby-twig
in your Composer dependencies:
Then, make sure your Kirby installation is autoloading Composer dependencies on both frontend and panel. For this, the safest way is to create your own custom plugin.
Finally, register the plugin by adding this line to your newly created site/plugins/composer/composer.php
, after having required the autoloader.
Usage
Page templates
Now that the plugin is installed and active, you can write Twig templates in the site/templates
directory. For example, if the text file for your articles is named post.txt
, you could have a post.twig
template like this:
See the {% extends '@templates/layout.twig' %}
and {% block content %}
parts? They’re a powerful way to manage having a common page layout for many templates, and only changing the core content (and/or other specific parts). Read our Twig templating guide for more information.
Rendering a template in PHP: the twig
helper
This plugin also enables a twig
PHP function for rendering template files and strings, like this:
If you work with Twig templates for pages, you might not need the twig()
helper at all. But it can be useful when working with the Modules and Patterns plugins.
More documentation
Recommended reads:
- Twig templating guide for Kirby
- Displaying Twig errors
Other topics:
- Complete options documentation
- Using your own functions in templates
- Using Kirby Twig with other plugins
Credits
- Twig library: Fabien Potencier and contributors / New BSD License
- Twig plugin for Kirby: Florens Verschelde / MIT License