diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index a09cc086c..710cfabfd 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -53,6 +53,7 @@ false %kernel.environment% + %kernel.debug% diff --git a/core/lib/Thelia/Core/EventListener/ViewListener.php b/core/lib/Thelia/Core/EventListener/ViewListener.php index 2b008dd17..894428760 100755 --- a/core/lib/Thelia/Core/EventListener/ViewListener.php +++ b/core/lib/Thelia/Core/EventListener/ViewListener.php @@ -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; /** diff --git a/core/lib/Thelia/Core/Template/Exception/ResourceNotFoundException.php b/core/lib/Thelia/Core/Template/Exception/ResourceNotFoundException.php new file mode 100644 index 000000000..c3d627123 --- /dev/null +++ b/core/lib/Thelia/Core/Template/Exception/ResourceNotFoundException.php @@ -0,0 +1,28 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Core\Template\Exception; + + +class ResourceNotFoundException extends \RuntimeException { + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php index 01a67e57a..88146317b 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php @@ -91,13 +91,12 @@ 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()); } + $template->assign('__COUNT__', 1 + $loopResults->key()); + $template->assign('__TOTAL__', $loopResults->getCount()); + $repeat = $loopResults->valid(); } diff --git a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php index 252f2256c..9f9df8a88 100755 --- a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php +++ b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php @@ -17,8 +17,10 @@ use Thelia\Core\Template\Exception\ResourceNotFoundException; /** * * @author Franck Allimant + * @author Etienne Roudeix */ -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) { diff --git a/core/lib/Thelia/Core/Template/Smarty/SmartyPluginDescriptor.php b/core/lib/Thelia/Core/Template/Smarty/SmartyPluginDescriptor.php index 3e8fec8ad..6d598b0ce 100755 --- a/core/lib/Thelia/Core/Template/Smarty/SmartyPluginDescriptor.php +++ b/core/lib/Thelia/Core/Template/Smarty/SmartyPluginDescriptor.php @@ -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 { /** diff --git a/core/lib/Thelia/Core/Template/Smarty/SmartyPluginInterface.php b/core/lib/Thelia/Core/Template/Smarty/SmartyPluginInterface.php index 87705c467..afbc7741f 100755 --- a/core/lib/Thelia/Core/Template/Smarty/SmartyPluginInterface.php +++ b/core/lib/Thelia/Core/Template/Smarty/SmartyPluginInterface.php @@ -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 diff --git a/templates/smarty-sample/index.html b/templates/smarty-sample/index.html index 512679551..9135b8867 100755 --- a/templates/smarty-sample/index.html +++ b/templates/smarty-sample/index.html @@ -1,5 +1,87 @@ -
    -{loop type="category" name="catloop1" id="1,3"} -
  • {$TITLE} - #TITLE
  • -{/loop} -
\ No newline at end of file +{include file="includes/header.html"} +
+An image from asset directory : +{images file='assets/img/logo-thelia-34px.png'}{intl l='Thelia, solution e-commerce libre'}{/images} +
+ +
+{intl l='An internationalized string'} +
+ +
+ jQuery data: +
+ +
+

Category loop example

+
    + {loop type="category" name="catloop1"} +
  • {$__COUNT__}/{$__TOTAL__} : {$ID} {$TITLE}, children: {$NB_CHILD} + {ifloop rel="inner1"} +
      + {loop type="category" name="inner1" parent="{$ID}"} +
    • Sub cat {$ID} (parent is {$PARENT}): {$TITLE}
    • + {/loop} +
    + {/ifloop} +
  • + {/loop} +
+
+ +
+

Conditional example #1

+ + {ifloop rel="catloop2"} + Hey ! Loop catloop2 is not empty: +
    + {loop type="category" name="catloop2" parent="12"} +
  • {$__COUNT__}/{$__TOTAL__} : {$ID} {$TITLE}
  • + {/loop} +
+ {/ifloop} + + {elseloop rel="catloop2"} +

Loop catloop2 is empty

+ {/elseloop} +
+ +
+

Conditional example #2

+ + {ifloop rel="catloop3"} + Loop catloop3 is not empty: +
    + {loop type="category" name="catloop3" parent="0"} +
  • {$__COUNT__}/{$__TOTAL__} : {$ID} {$TITLE}
  • + {/loop} +
+ {/ifloop} + + {elseloop rel="catloop3"} +

Loop catloop3 is empty

+ {/elseloop} + + {elseloop rel="catloop2"} +

... but catloop2 is still empty :-)

+ {/elseloop} + {ifloop rel="catloop1"} +

... and catloop1 is still NOT empty :-)

+ {/ifloop} +
+ +
+

Traditional for loop

+ {for $index=5 to 12 step 1} + Compteur = {$index}
+ {/for} +
+ +
+

Loops also work with #

+ {loop type="category" name="catloop1"} + #TITLE : {#DESCRIPTION|upper} #NOTATAG
+ {/loop} +
+ +{include file="includes/footer.html"} \ No newline at end of file