<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[twig - Stapps.io]]></title><description><![CDATA[twig - Stapps.io]]></description><link>https://blog.stapps.io/</link><generator>Ghost 0.11</generator><lastBuildDate>Fri, 02 Jan 2026 14:41:38 GMT</lastBuildDate><atom:link href="https://blog.stapps.io/tag/twig/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Twig Playground]]></title><description><![CDATA[<p>I've been playing around with Twig templating alot lately, we're implementing it in one of our core projects at work. </p>

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

<p>It's easy enough to download with</p>]]></description><link>https://blog.stapps.io/twig-playground/</link><guid isPermaLink="false">799f7344-0995-4866-b7fa-405d02fad54e</guid><category><![CDATA[twig]]></category><category><![CDATA[php]]></category><dc:creator><![CDATA[Andrew Stilliard]]></dc:creator><pubDate>Thu, 04 Dec 2014 09:44:36 GMT</pubDate><content:encoded><![CDATA[<p>I've been playing around with Twig templating alot lately, we're implementing it in one of our core projects at work. </p>

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

<p>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. <br>
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.</p>

<p>It's called Twig playground: <br>
<a href="http://twig.stapps.io/">http://twig.stapps.io/</a></p>

<p>Plus it's open source: <br>
<a href="https://github.com/stilliard/twig-playground">https://github.com/stilliard/twig-playground</a></p>

<p>It's not perfect, but it works for now.</p>

<p><em>(To edit file names btw, just double click on the name, you can then also delete the file)</em></p>

<h2 id="givemeanexample">Give me an example:</h2>

<p>Ok, try it out creating the following 4 files as a simple demo:</p>

<p><em>index.html.twig:</em></p>

<pre><code class="language-twig">{% extends "layout.html.twig" %}

{% block main %}
&lt;h1&gt;{{ text | title }}&lt;/h1&gt;  
&lt;ul&gt;  
{% for item in items %}
    &lt;li&gt;{{ item.name }}&lt;/li&gt;
{% endfor %}
&lt;/ul&gt;  
{% endblock %}
</code></pre>

<p><em>layout.html.twig:</em></p>

<pre><code class="language-twig">&lt;!DOCTYPE html&gt;  
&lt;html&gt;  
&lt;head&gt;  
&lt;meta charset="utf-8"&gt;  
&lt;title&gt;Demo&lt;/title&gt;  
&lt;/head&gt;  
&lt;body&gt;

&lt;header&gt;{% include 'header.html.twig' %}&lt;/header&gt;

&lt;div class="main"&gt;  
{% block main %}{% endblock %}
&lt;/div&gt;

&lt;footer&gt;{% include 'footer.html.twig' %}&lt;/footer&gt;

&lt;/body&gt;  
&lt;/html&gt;  
</code></pre>

<p><em>header.html.twig:</em></p>

<pre><code class="language-twig">... header ...
</code></pre>

<p><em>footer.html.twig:</em></p>

<pre><code class="language-twig">... footer ...
</code></pre>

<hr>

<p>It also supports css output, just rename the first file as .css.twig</p>

<p>E.g. Try the following in the playground:</p>

<p><em>JSON variables:</em></p>

<pre><code class="language-javascript">{ "header_color": "blue" }
</code></pre>

<p><em>index.css.twig:</em></p>

<pre><code class="language-twig">{% include 'base.css' %}

.body { background: {{ header_color }}; }
</code></pre>

<p><em>base.css:</em></p>

<pre><code class="language-css">body { font: 13px/1.4 sans-serif; }  
.header { ...}
.footer { ... }
</code></pre>]]></content:encoded></item></channel></rss>