I'm in the midst of writing a basic application using Phalcon & Volt and plan on comparing the performance with the same application, written using plain PHP and Twig. Whilst re-writing this application, I've noticed a few things which either work differently in Volt or do not work at all like Twig.
Consider the following layout and child template.
base.layout.volt
<html>
<head>
{% block head %}
<title>{{ title | default('Base Layout') }}</title>
{% endblock %}
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>
child.template.volt
{% extends 'base.layout.volt' %}
{% set title = 'Child Title' %}
{% set heading = 'Child Heading' %}
{% block head %}
{{ super() }}
<style type="text/css">
.message { color: #336699; }
</style>
{% endblock %}
{% block content %}
<h1>{{ heading }}</h1>
<p class="message">
{{ message }}
</p>
{% endblock %}
The above works fine in Twig, however if you try to render this with Volt you'll receive an error message like:
Child templates only may contain blocks in..
This error is caused by setting the variable values title
& heading
outside a block
definition. While I understand adding HTML content outside of a block
definition would never be allowed, I don't understand why variables cannot be set this way? In my oppinion those variables title
& heading
are global and should be declared in the same scope as the view
variables and override them if they exist.