Use # as tag delimiter

Merge branch 'admin' into argument
This commit is contained in:
Etienne Roudeix
2013-06-24 16:18:32 +02:00
8 changed files with 140 additions and 15 deletions

View File

@@ -53,6 +53,7 @@
<argument type="service" id="event_dispatcher"/>
<argument >false</argument>
<argument >%kernel.environment%</argument>
<argument >%kernel.debug%</argument>
</service>
<!-- Smarty parser plugins -->

View File

@@ -28,7 +28,7 @@ use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Thelia\Core\Template\Exception\ResourceNotFoundException;
use Thelia\Core\Template\ParserInterface;
/**

View File

@@ -0,0 +1,28 @@
<?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\Exception;
class ResourceNotFoundException extends \RuntimeException {
}

View File

@@ -91,12 +91,11 @@ class TheliaLoop implements SmartyPluginInterface
$loopResultRow = $loopResults->current();
foreach($loopResultRow->getVarVal() as $var => $val) {
$template->assign(substr($var, 1), $val);
}
$template->assign('__COUNT__', 1 + $loopResults->key());
$template->assign('__TOTAL__', $loopResults->getCount());
}
$repeat = $loopResults->valid();
}

View File

@@ -17,8 +17,10 @@ use Thelia\Core\Template\Exception\ResourceNotFoundException;
/**
*
* @author Franck Allimant <franck@cqfdev.fr>
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*/
class SmartyParser extends Smarty implements ParserInterface {
class SmartyParser extends Smarty implements ParserInterface
{
public $plugins = array();
@@ -66,6 +68,7 @@ class SmartyParser extends Smarty implements ParserInterface {
$this->compile_check = true;
} else {
$this->caching = Smarty::CACHING_OFF;
$this->force_compile = true;
}
// The default HTTP status
@@ -76,11 +79,10 @@ class SmartyParser extends Smarty implements ParserInterface {
public function pretest($tpl_source, \Smarty_Internal_Template $template)
{
echo 1;
$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);
return $tpl_source;
//return $tpl_source;
return $new_source;
}
public function setTemplate($template_path_from_template_base) {

View File

@@ -23,6 +23,12 @@
namespace Thelia\Core\Template\Smarty;
/**
* Class allowing to describe a smarty plugin
*
* Class SmartyPluginDescriptor
* @package Thelia\Core\Template\Smarty
*/
class SmartyPluginDescriptor {
/**

View File

@@ -23,6 +23,13 @@
namespace Thelia\Core\Template\Smarty;
/**
*
* this interface must be implements when you want to add plugin to smarty using config process
*
* Interface SmartyPluginInterface
* @package Thelia\Core\Template\Smarty
*/
interface SmartyPluginInterface {
/**
* @return an array of SmartyPluginDescriptor

View File

@@ -1,5 +1,87 @@
<ul>
{loop type="category" name="catloop1" id="1,3"}
<li>{$TITLE} - #TITLE</li>
{/loop}
</ul>
{include file="includes/header.html"}
<div>
An image from asset directory :
{images file='assets/img/logo-thelia-34px.png'}<img src="{$asset_url}" alt="{intl l='Thelia, solution e-commerce libre'}" />{/images}
</div>
<div>
{intl l='An internationalized string'}
</div>
<div>
jQuery data: <span id="jquery_block"></span>
</div>
<div>
<p>Category loop example</p>
<ul>
{loop type="category" name="catloop1"}
<li>{$__COUNT__}/{$__TOTAL__} : {$ID} {$TITLE}, children: {$NB_CHILD}
{ifloop rel="inner1"}
<ul>
{loop type="category" name="inner1" parent="{$ID}"}
<li>Sub cat {$ID} (parent is {$PARENT}): {$TITLE}</li>
{/loop}
</ul>
{/ifloop}
</li>
{/loop}
</ul>
</div>
<div>
<p>Conditional example #1</p>
{ifloop rel="catloop2"}
Hey ! Loop catloop2 is not empty:
<ul>
{loop type="category" name="catloop2" parent="12"}
<li>{$__COUNT__}/{$__TOTAL__} : {$ID} {$TITLE}</li>
{/loop}
</ul>
{/ifloop}
{elseloop rel="catloop2"}
<p>Loop catloop2 is empty</p>
{/elseloop}
</div>
<div>
<p>Conditional example #2</p>
{ifloop rel="catloop3"}
Loop catloop3 is not empty:
<ul>
{loop type="category" name="catloop3" parent="0"}
<li>{$__COUNT__}/{$__TOTAL__} : {$ID} {$TITLE}</li>
{/loop}
</ul>
{/ifloop}
{elseloop rel="catloop3"}
<p>Loop catloop3 is empty</p>
{/elseloop}
{elseloop rel="catloop2"}
<p>... but catloop2 is still empty :-)</p>
{/elseloop}
{ifloop rel="catloop1"}
<p>... and catloop1 is still NOT empty :-)</p>
{/ifloop}
</div>
<div>
<p>Traditional for loop</p>
{for $index=5 to 12 step 1}
Compteur = {$index}<br />
{/for}
</div>
<div>
<p>Loops also work with #</p>
{loop type="category" name="catloop1"}
#TITLE : {#DESCRIPTION|upper} #NOTATAG<br />
{/loop}
</div>
{include file="includes/footer.html"}