I've got a problem integrating Twig and Zend Framework 1, with the Zwig library alb/zwig,
Versions are
alb/zwig version 1.0.1 twig/twig 1.14.2 zf1 1.12.3
The result is:
- module controller action call is fine
- layout.twig is properly displayed (parent() works)
- index.twig specific block content is not displayed
Trials: several downgrades, no step by step debug performed
application/configs/application.ini
twig.templateDir = APPLICATION_PATH "/modules/%module%/views/scripts/"
;twig.options.cache = APPLICATION_PATH "/../cache/twig"
autoloaderNamespaces[] = "Twig_"
autoloaderNamespaces[] = "Zwig_"
autoloaderNamespaces[] = "ZFDebug_"
resources.modules[] = ""
resources.layout.layoutPath = APPLICATION_PATH "/modules/Layout/views/scripts/"
resources.layout.layout = "layout"
application/Bootstrap.php
public function _initLayout() {
$layout = $this->getPluginResource("layout")->getLayout();
$layout->setViewSuffix("twig");
}
protected function _initTwig() {
Twig_Autoloader::register();
$config = Zend_Registry::get('config');
$templatePath = array();
$view = new Zwig_View(array(
'encoding' => 'UTF-8',
'helperPath' => array(
),
));
$loader = new Twig_Loader_Filesystem();
$d = new DirectoryIterator($config->resources->frontController->moduleDirectory);
foreach ($d as $fileInfo) {
zif (!$fileInfo->isDot() && $fileInfo->isDir()) {
$moduleName = $fileInfo->getFilename();
$templatePath =
str_replace(
'%module%', $moduleName, $config->twig->templateDir
);
$loader->addPath($templatePath, strtolower($moduleName));
}
}
$zwig = new Zwig_Environment($view, $loader, array(
'debug' => true,
'cache' => APPLICATION_PATH . '/cache/twig/',
//'auto_reload' => true,
));
$view->setEngine($zwig);
$view->doctype(Zend_View_Helper_Doctype::XHTML1_STRICT);
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view, array(
'viewSuffix' => 'twig',
));
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
return $view;
}
application/modules/Login/controllers/IndexController.php
class Login_IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
$this->view->toto = "texte";
}
}
application/modules/Layout/views/scripts/layout.twig
{# empty Twig template #}
Titre de la page
{% block header %}
{%endblock header %}
{% block content %}
eéâà
{% endblock content %}
{% block sidebar %}
{% endblock sidebar %}
ceci est un contenu de page
child template
# cat application/modules/Login/views/scripts/index/index.twig
{% extends '@layout/layout.twig' %}
{% block content %}
{{ parent() }}
{{ toto }}
{% endblock content %}