check type in Smarty plugin
This commit is contained in:
@@ -237,7 +237,15 @@ class TheliaLoop implements SmartyPluginInterface {
|
||||
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) {
|
||||
$value = $argument->default;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ class TypeCollection implements \Iterator
|
||||
* (PHP 5 >= 5.0.0)<br/>
|
||||
* Return the current element
|
||||
* @link http://php.net/manual/en/iterator.current.php
|
||||
* @return \Thelia\Core\Template\Element\LoopResultRow
|
||||
* @return \Thelia\Type\TypeInterface
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
@@ -116,4 +116,25 @@ class TypeCollection implements \Iterator
|
||||
{
|
||||
$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>
|
||||
{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>
|
||||
|
||||
{include file="includes/footer.html"}
|
||||
<ul>
|
||||
{loop type="category" name="catloop1" id="1,3"}
|
||||
<li>{$TITLE}</li>
|
||||
{/loop}
|
||||
</ul>
|
||||
Reference in New Issue
Block a user