All Projects → fvsch → Kirby Twig

fvsch / Kirby Twig

Licence: mit
Twig templating support for Kirby CMS 2. For Kirby 3, use https://github.com/amteich/kirby-twig

Projects that are alternatives of or similar to Kirby Twig

Graphql Modules
⚠️ [DEPRECATED] GraphQL module library for Apollo.
Stars: ✭ 53 (-27.4%)
Mutual labels:  deprecated
Twoot
An open source light-weight OS X twitter client based on jQuery and Fluid (deprecated!)
Stars: ✭ 61 (-16.44%)
Mutual labels:  deprecated
Django Cache Url
DEPRECATED | Use Cache URLs in your Django Application
Stars: ✭ 68 (-6.85%)
Mutual labels:  deprecated
Face Recognition
Deprecated. Face recognition Android application. Using Android SDK, OpenCV and Facebook SDK. Loading the user's Facebook pictures, scanning pictures for facial features and comparing faces to image repository for matches. PLEASE NOTE: This project is relatively old and uses obsolete versions of both the Facebook SDK and the Android SDK.
Stars: ✭ 54 (-26.03%)
Mutual labels:  deprecated
Anatine
[DEPRECATED] 🐦 Pristine Twitter app
Stars: ✭ 1,102 (+1409.59%)
Mutual labels:  deprecated
Conductor
Conductor makes it easy to mange multiple composer packages within a single source repository
Stars: ✭ 64 (-12.33%)
Mutual labels:  deprecated
Terminal Ide
💀 A full command line based Java / Android develpment kit, that runs on Android devices.
Stars: ✭ 52 (-28.77%)
Mutual labels:  deprecated
Grunt Myth
Myth - Postprocessor that polyfills CSS
Stars: ✭ 70 (-4.11%)
Mutual labels:  deprecated
System
A full-stack framework built from Aura library packages.
Stars: ✭ 61 (-16.44%)
Mutual labels:  deprecated
Onedrive Fuse Fs
Script to mount Microsoft OneDrive (formerly known as SkyDrive) folder as a FUSE filesystem
Stars: ✭ 68 (-6.85%)
Mutual labels:  deprecated
Os Homedir
[DEPRECATED] Node.js `os.homedir()` ponyfill
Stars: ✭ 55 (-24.66%)
Mutual labels:  deprecated
Notifier For Github Firefox
[DEPRECATED] Firefox extension - Displays your GitHub notifications unread count
Stars: ✭ 58 (-20.55%)
Mutual labels:  deprecated
Dashboard Extension Online Map Item
⛔ DEPRECATED. This project was moved to a new repository. Visit https://github.com/DevExpress/dashboard-extensions to find an updated version.
Stars: ✭ 65 (-10.96%)
Mutual labels:  deprecated
Dataarrays.jl
DEPRECATED: Data structures that allow missing values
Stars: ✭ 54 (-26.03%)
Mutual labels:  deprecated
Entware Ng
Entware-ng
Stars: ✭ 1,157 (+1484.93%)
Mutual labels:  deprecated
Android Lint Plugin
Android Lint parser plugin for Jenkins
Stars: ✭ 52 (-28.77%)
Mutual labels:  deprecated
Dashboard Extension Webpage Item
⛔ DEPRECATED. This project was moved to a new repository. Visit https://github.com/DevExpress/dashboard-extensions to find an updated version.
Stars: ✭ 62 (-15.07%)
Mutual labels:  deprecated
Sphero Mac Sdk
🚫 DEPRECATED: Sphero SDK for the Mac platform.
Stars: ✭ 70 (-4.11%)
Mutual labels:  deprecated
Panel Bar
panelBar for Kirby 2 CMS
Stars: ✭ 70 (-4.11%)
Mutual labels:  kirby-plugin
Merx
Merx is a plugin to create online shops with Kirby 3.
Stars: ✭ 66 (-9.59%)
Mutual labels:  kirby-plugin

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:

<?php /* site/templates/hello.php */ ?>
<h1><?= $page->title() ?></h1>
<ul>
<?php foreach ($page->children() as $child): ?>
  <li><a href="<?= $child->url() ?>"><?= $child->title() ?></li>
<?php endforeach; ?>
</ul>

After:

{# site/templates/hello.twig #}
<h1>{{ page.title }}</h1>
<ul>
{% for child in page.children %}
  <li><a href="{{ child.url }}">{{ child.title }}</li>
{% endfor %}
</ul>

Installation

Standard installation

  1. Download the latest release.
  2. Unzip, rename the kirby-twig-main folder to just twig and put it in your project’s site/plugins folder.

You should end up with a folder structure like this:

site
 └─ plugins
     └─ twig
         ├─ lib
         ├─ src
         └─ twig.php

Using Composer

Require fvsch/kirby-twig in your Composer dependencies:

composer require fvsch/kirby-twig:^3.0

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.

site
 └─ plugins
     └─ composer
         └─ composer.php
<?php
// site/plugins/composer/composer.php

// Composer autoload
require_once kirby()->roots()->index() . '/vendor/autoload.php';

Finally, register the plugin by adding this line to your newly created site/plugins/composer/composer.php, after having required the autoloader.

// Register the Twig plugin's template component
Kirby\Twig\Plugin::register();

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:

{% extends '@templates/layout.twig' %}
{% block content %}
  <article>
    <h1>{{ page.title }}</h1>
    {{ page.text.kirbytext | raw }}
  </article>
{% endblock %}

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:

<?php

// Render a simple template from the site/snippets directory
echo twig('@snippets/header.twig');

// Same, but passing some additionnal variables
echo twig('@snippets/header.twig', ['sticky'=>false]);

// Render a string
echo twig('Hello {{ who }}', ['who'=>'World!']);

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:

Other topics:

Credits

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].