fix thelia diese problems

This commit is contained in:
Etienne Roudeix
2013-07-03 16:07:18 +02:00
parent b5d9f69212
commit 3073f9a43c
5 changed files with 67 additions and 7 deletions

View File

@@ -67,6 +67,10 @@
<tag name="thelia.parser.register_plugin"/> <tag name="thelia.parser.register_plugin"/>
</service> </service>
<service id="smarty.plugin.theliasyntax" class="Thelia\Core\Template\Smarty\Plugins\TheliaSyntax" >
<tag name="thelia.parser.register_plugin"/>
</service>
<service id="smarty.plugin.thelialoop" class="Thelia\Core\Template\Smarty\Plugins\TheliaLoop" scope="request"> <service id="smarty.plugin.thelialoop" class="Thelia\Core\Template\Smarty\Plugins\TheliaLoop" scope="request">
<tag name="thelia.parser.register_plugin"/> <tag name="thelia.parser.register_plugin"/>

View File

@@ -29,7 +29,7 @@ class LoopResultRow
public function set($key, $value) public function set($key, $value)
{ {
$this->substitution[$key] = $value; $this->substitution[$key] = $value === null ? '' : $value;
} }
public function get($key) public function get($key)

View File

@@ -0,0 +1,54 @@
<?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 Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use Thelia\Core\Template\Smarty\SmartyPluginInterface;
/**
* Class TheliaSyntax
* @package Thelia\Core\Template\Smarty\Plugins
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*/
class TheliaSyntax implements SmartyPluginInterface
{
public function dieseCancel($value, $diese)
{
if($value === null) {
return $diese;
}
return $value;
}
/**
* @return SmartyPluginDescriptor[]
*/
public function getPluginDescriptors()
{
return array(
new SmartyPluginDescriptor("modifier", "dieseCanceller", $this, "dieseCancel")
);
}
}

View File

@@ -29,10 +29,11 @@ class SmartyParser extends Smarty implements ParserInterface
protected $status = 200; protected $status = 200;
/** /**
* @param \Symfony\Component\HttpFoundation\Request $request * @param Request $request
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher * @param EventDispatcherInterface $dispatcher
* @param bool $template * @param bool $template
* @param string $env Environment define for the kernel application. Used for the cache directory * @param string $env
* @param bool $debug
*/ */
public function __construct(Request $request, EventDispatcherInterface $dispatcher, $template = false, $env = "prod", $debug = false) public function __construct(Request $request, EventDispatcherInterface $dispatcher, $template = false, $env = "prod", $debug = false)
{ {
@@ -78,7 +79,7 @@ class SmartyParser extends Smarty implements ParserInterface
public function preThelia($tpl_source, \Smarty_Internal_Template $template) public function preThelia($tpl_source, \Smarty_Internal_Template $template)
{ {
$new_source = preg_replace('`{#([a-zA-Z][a-zA-Z0-9\-_]*)(.*)}`', '{\$$1$2}', $tpl_source); $new_source = preg_replace('`{#([a-zA-Z][a-zA-Z0-9\-_]*)(.*)}`', '{\$$1$2}', $tpl_source);
$new_source = preg_replace('`#([a-zA-Z][a-zA-Z0-9\-_]*)`', '{\$$1|default:\'#$1\'}', $new_source); $new_source = preg_replace('`#([a-zA-Z][a-zA-Z0-9\-_]*)`', '{\$$1|dieseCanceller:\'#$1\'}', $new_source);
return $new_source; return $new_source;
} }

View File

@@ -19,10 +19,11 @@
<hr /> <hr />
{/loop*} {/loop*}
<h2>PRODUCTS</h2> <h2>PRODUCTS</h2>
{loop name="product" type="product" min_weight="2.5" max_weight="10"} {loop name="product" type="product"}
<h3>PRODUCT : #REF / #TITLE</h3> <h3>PRODUCT : #REF / #TITLE</h3>
price : #PRICE €<br /> price : #PRICE €<br />
promo price : #PROMO_PRICE €<br /> promo price : #PROMO_PRICE €<br />
is promo : #PROMO<br /> is promo : #PROMO<br />
is new : #NEW<br />
weight : #WEIGHT<br /> weight : #WEIGHT<br />
{/loop} {/loop}