Closed Alfredao closed 4 years ago
With this configuration
'zend_twig' => [
'force_twig_strategy' => false,
],
If I return the json model like this
public function indexAction()
{
return new JsonModel([
'testing' => 'Hello World'
]);
}
I get the result as expected. See below
But instead of JsonModel, if I return a TwigModel, the twig files does not render
public function indexAction()
{
return new TwigModel([
'testing' => 'Hello World'
]);
}
Result
@Alfredao could you provide your configuration for module here and order of the modules in your application config (this module should be in the end, because of a way how zf3 is loading dependencies).
Hi @OxCom
My module order is
return [
'Zend\Mvc\I18n',
'Zend\Hydrator',
'Zend\Router',
'Zend\Validator',
'DoctrineModule',
'DoctrineORMModule',
'Ecommerce',
'ZendTwig',
];
This configuration is in Ecommerce module config
'zend_twig' => [
'force_twig_strategy' => false,
'force_standalone' => false,
'invoke_zend_helpers' => true,
'environment' => [
],
'loader_chain' => [
\ZendTwig\Loader\MapLoader::class,
\ZendTwig\Loader\StackLoader::class,
],
'extensions' => [
\Ecommerce\View\Twig\Extension\Slugify::class,
\Ecommerce\View\Twig\Extension\Money::class,
],
'helpers' => [
'configs' => [
\Zend\Navigation\View\HelperConfig::class,
],
],
],
@Alfredao CNR: Just checked in empty zend-skeleton. With the same configuration.
Please check what type of the template do you have for this indexAction()
? It should be index.twig
not index.phtml
. Please check example
run:
composer install
cd ./public
php -S localhost:8000
check:
curl -D- http://127.0.0.1:8000/application/json
curl -D- http://127.0.0.1:8000/application/twig
curl -D- http://127.0.0.1:8000/application/index
@OxCom Thank you for your time, this works ok.
But can we render the layout/layout configured in template_map with Twig as well?
'view_manager' => [
'template_map' => [
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml', // this one with Twig
],
],
My plan is to give a template example for others developers create it's own layout, like Shopify does. So its better for the template to be only twig files.
@Alfredao change it to layout.twig
and then use twig syntax. Example:
{{ docType() }}
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
{{ headTitle('Hello World')|raw }}
{{
headMeta()
.appendName('viewport', 'width=device-width, initial-scale=1.0')
.appendName('subject', 'Hello subject.')
.appendName('description', 'World description.')
.appendHttpEquiv('X-UA-Compatible', 'IE=edge')
|raw
}}
{{
headLink()
.headLink({
'rel' : 'shortcut icon',
'type' : 'image/vnd.microsoft.icon',
'href' : ServerUrl('/img/favicon.ico'),
})
.appendStylesheet(ServerUrl('/css/styles.min.css'))
|raw
}}
</head>
<body>
{% block content %}
{{ content|raw }}
{% endblock content %}
{% block content_scripts %}
{{ content_scripts|default('')|raw }}
{% endblock content_scripts %}
</body>
</html>
Sorry for not giving enough information, but that is my problem. If I change layout.phtml extension to twig it can't be rendered. Look
I could not find the problem, but I think ZendView is rendering the layout.twig file as PHP and this module is rendering only the content files
@Alfredao please update to the latest version with a fix.
Hi @OxCom, tested yesterday! Thank you so much
Hi
I'm having the same problem as #9, when returning a JsonModel instance, I got this fatal error instead of the json response.
If I set
force_twig_strategy
tofalse
, the JsonModel returns the json correctly, but then TwigModel does not render the twig templatesThere's something I can do to solve this problem? Thank you all