check type in Smarty plugin
This commit is contained in:
@@ -237,7 +237,15 @@ class TheliaLoop implements SmartyPluginInterface {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check default */
|
/* check type */
|
||||||
|
if($value !== null && !$argument->type->isValid($value)) {
|
||||||
|
$faultActor[] = $argument->name;
|
||||||
|
$faultDetails[] = sprintf('Invalid value for "%s" argument', $argument->name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set default */
|
||||||
|
/* did it as last checking for we consider default value is acceptable no matter type or empty restriction */
|
||||||
if($value === null) {
|
if($value === null) {
|
||||||
$value = $argument->default;
|
$value = $argument->default;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class TypeCollection implements \Iterator
|
|||||||
* (PHP 5 >= 5.0.0)<br/>
|
* (PHP 5 >= 5.0.0)<br/>
|
||||||
* Return the current element
|
* Return the current element
|
||||||
* @link http://php.net/manual/en/iterator.current.php
|
* @link http://php.net/manual/en/iterator.current.php
|
||||||
* @return \Thelia\Core\Template\Element\LoopResultRow
|
* @return \Thelia\Type\TypeInterface
|
||||||
*/
|
*/
|
||||||
public function current()
|
public function current()
|
||||||
{
|
{
|
||||||
@@ -116,4 +116,25 @@ class TypeCollection implements \Iterator
|
|||||||
{
|
{
|
||||||
$this->position = 0;
|
$this->position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $value
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isValid($value)
|
||||||
|
{
|
||||||
|
$this->rewind();
|
||||||
|
while ($this->valid()) {
|
||||||
|
$type = $this->current();
|
||||||
|
|
||||||
|
if($type->isValid($value)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->next();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,80 +1,5 @@
|
|||||||
{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>
|
<ul>
|
||||||
{loop type="category" name="catloop1"}
|
{loop type="category" name="catloop1" id="1,3"}
|
||||||
<li>{$__COUNT__}/{$__TOTAL__} : {$ID} {$TITLE}, children: {$NB_CHILD}
|
<li>{$TITLE}</li>
|
||||||
{ifloop rel="inner1"}
|
|
||||||
<ul>
|
|
||||||
{loop type="category" name="inner1" parent="{$ID}"}
|
|
||||||
<li>Sub cat {$ID} (parent is {$PARENT}): {$TITLE}</li>
|
|
||||||
{/loop}
|
{/loop}
|
||||||
</ul>
|
</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>
|
|
||||||
|
|
||||||
{include file="includes/footer.html"}
|
|
||||||
Reference in New Issue
Block a user