Ok. I use Twig as a View engine and Phalcon version is 0.8
Code of adapter I got from this repository: github I made a small modification in this code because I include Twig via composer. I will not describe these modifications because they are not significant.
So. My directory structure of view is very simple:
app
- views
--- index.twig
--- about
---- index.twig
Source of views/index.twig:
<html>
<head>
<title>Phalcon PHP Framework</title>
</head>
<body>
{% block content 'This is main page' %}
</body>
</html>
And source of views/about/index.twig:
{% extends "index.twig" %}
{% block content %}
This is About page
{% endblock %}
Also, I have controller About (AboutController.php) with single method
public function indexAction()
it’s empty.
Ok. Now. When I do a request for a page /about I expect to see there something like this:
This is About page
But I still see there content of views/index.twig:
This is main page
It’s a bit strange to me. I reassign the block “content”!
I did some checking in the template views/about/index.twig adding extra characters out of the block and I received an error from Twig:
A template that extends another one cannot have a body in "about/index.twig"
So. Any ideas?
P.S. I think I should call in tpl views/index.twig method {{ content() }} but Twig knows nothing about this method.
The problem was that I was not good enough to read the documentation!
To solve my issue I had to use render levels of templates in View component: official docs
To use the built-in export function in Twig and use a powerful mechanism of inheritance of this engine,
we must set level render:
In this case, the engine will immediately process the contents of the template action.