Twig Playground

I've been playing around with Twig templating alot lately, we're implementing it in one of our core projects at work.

Twig a great language for templating, with filters and the ability to extend blocks of other templates it works perfectly for our development flow.

It's easy enough to download with composer and get started with it, but I think I've been spoiled by alot of langauges with REPLs / interactive shells.
So i build a little web interface that allows me to enter some test variables (via JSON), multiple files (to test out includes and extending) and a fast way to render the results.

It's called Twig playground:

Plus it's open source:

It's not perfect, but it works for now.

(To edit file names btw, just double click on the name, you can then also delete the file)

Give me an example:

Ok, try it out creating the following 4 files as a simple demo:


{% extends "layout.html.twig" %}

{% block main %}
<h1>{{ text | title }}</h1>  
{% for item in items %}
    <li>{{ }}</li>
{% endfor %}
{% endblock %}


<!DOCTYPE html>  
<meta charset="utf-8">  

<header>{% include 'header.html.twig' %}</header>

<div class="main">  
{% block main %}{% endblock %}

<footer>{% include 'footer.html.twig' %}</footer>



... header ...


... footer ...

It also supports css output, just rename the first file as .css.twig

E.g. Try the following in the playground:

JSON variables:

{ "header_color": "blue" }


{% include 'base.css' %}

.body { background: {{ header_color }}; }


body { font: 13px/1.4 sans-serif; }  
.header { ...}
.footer { ... }
comments powered by Disqus
Want to setup your own server? Digital Ocean offer $10 free for new accounts.