create smarty tag for smarty renderer
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
<parameters>
|
||||
<parameter key="esi.class">Symfony\Component\HttpKernel\HttpCache\Esi</parameter>
|
||||
<parameter key="esi_listener.class">Symfony\Component\HttpKernel\EventListener\EsiListener</parameter>
|
||||
<parameter key="fragment.renderer.esi.class">Symfony\Component\HttpKernel\Fragment\EsiFragmentRenderer</parameter>
|
||||
<parameter key="fragment.renderer.inline.class">Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
@@ -24,6 +26,14 @@
|
||||
<service id="esi_listener" class="%esi_listener.class%">
|
||||
<tag name="kernel.event_subscriber" />
|
||||
<argument type="service" id="esi" on-invalid="ignore" />
|
||||
</service>
|
||||
<service id="fragment.renderer.inline" class="%fragment.renderer.inline.class%">
|
||||
<argument type="service" id="http_kernel" />
|
||||
</service>
|
||||
|
||||
<service id="fragment.renderer.esi" class="%fragment.renderer.esi.class%">
|
||||
<argument type="service" id="esi" />
|
||||
<argument type="service" id="fragment.renderer.inline" />
|
||||
</service>
|
||||
<!--
|
||||
A ControllerResolver that supports "a:b:c", "service:method" and class::method" notations,
|
||||
|
||||
@@ -91,7 +91,11 @@
|
||||
<argument type="service" id="request" />
|
||||
</service>
|
||||
|
||||
|
||||
<service id="smarty.plugin.esi" class="Thelia\Core\Template\Smarty\Plugins\Esi" scope="request">
|
||||
<tag name="thelia.parser.register_plugin"/>
|
||||
<argument type="service" id="fragment.renderer.esi" />
|
||||
<argument type="service" id="request" />
|
||||
</service>
|
||||
|
||||
</services>
|
||||
|
||||
|
||||
82
core/lib/Thelia/Core/Template/Smarty/Plugins/Esi.php
Normal file
82
core/lib/Thelia/Core/Template/Smarty/Plugins/Esi.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Template\Smarty\Plugins;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Fragment\EsiFragmentRenderer;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Core\Template\Smarty\an;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
|
||||
|
||||
/**
|
||||
* Class Esi
|
||||
* @package Thelia\Core\Template\Smarty\Plugins
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class Esi extends AbstractSmartyPlugin
|
||||
{
|
||||
|
||||
protected $esiFragmentRender;
|
||||
protected $request;
|
||||
|
||||
public function __construct(EsiFragmentRenderer $esiFragmentRenderer, Request $request)
|
||||
{
|
||||
$this->esiFragmentRender = $esiFragmentRenderer;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function renderEsi($params, $template = null)
|
||||
{
|
||||
$path = $this->getParam($params, 'path');
|
||||
$alt = $this->getParam($params, 'alt');
|
||||
$ignore_errors = $this->getParam($params, 'ignore_errors');
|
||||
$comment = $this->getParam($params, 'comment');
|
||||
|
||||
if(null === $path) {
|
||||
return;
|
||||
}
|
||||
|
||||
$response = $this->esiFragmentRender->render($path, $this->request, array(
|
||||
'alt' => $alt,
|
||||
'ignore_errors' => $ignore_errors,
|
||||
'comment' => $comment
|
||||
));
|
||||
|
||||
if (!$response->isSuccessful()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $response->getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an array of SmartyPluginDescriptor
|
||||
*/
|
||||
public function getPluginDescriptors()
|
||||
{
|
||||
return array(
|
||||
new SmartyPluginDescriptor('function', 'render_esi', $this, 'renderEsi')
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -129,7 +129,7 @@ GNU General Public License : http://www.gnu.org/licenses/
|
||||
</div>
|
||||
</li>
|
||||
{/elseloop}
|
||||
<esi:include src="{url path="/mini-cart"}" alt="fail" ></esi:include>
|
||||
{render_esi path="{url path="/mini-cart"}" alt="fail"}
|
||||
</ul>
|
||||
{/nocache}
|
||||
<ul class="nav navbar-nav navbar-categories">
|
||||
|
||||
Reference in New Issue
Block a user