all im trying to do is to use the simple continue tag but it keeps giving me error like this:
string(145) "Smarty error: [in module_db_tpl:onlyimage4;image_detail line 26]: syntax error: unrecognized tag 'continue' (Smarty_Compiler.class.php, line 590)"
my code is as follow:
{foreach from=$itemlist item="item"}
< .. SOME CODE ..>
{if $maxCol == $colm}
</div>
{assign var ='colm' value = 0}
{$row++}
{continue} **<- THIS IS THE PROBLEM**
{/if}
<.. SOME CODE ..>
{/foreach}
does anyone have any idea whats wrong, I've been googling and see no comments of such sort everyone seem to suggest that this should work.. any ideas guys...
Old question, but you need to use: {$continue} (including the $)
For smarty 2:
I don't think the tag exists. if you read this thread you can see that there are people that want it, and a suggestion to fix it like so. (have not tried)
compiler.continue.php
<?php
function smarty_compiler_continue($contents, &$smarty)
{
return 'continue;';
}
?>
(Bold part my addition)
Create these two files (in this case just one) and put them into your plugins directory
(notice the naming convention compiler.xxx.php).
The good news is, for smarty 3 there is such a tag! see the manual, with example:
{$data = [1,2,3,4,5]}
{foreach $data as $value}
{if $value == 3}
{* skip this iteration *}
{continue}
{/if}
{$value}
{/foreach}
{*
prints: 1 2 4 5
*}
Related
what is the similar blade syntax for the following code?
<?php if(...):?>abc<?php else:?>cde<?php endif;?>
the code
#if(...) abc #else .... is no good as it ads a space before and after the "abc" the code #if(...)abc#endif (no spacing before and after html string) generates error ...
Thanks
Solution
The correct solution for this problem would be following:
#if(1==1){{ '1' }}#endif
This happens often and makes problem with "space sensitive" parts of code like values in <option> tags.
Having the #if(1==1) 1 #endif would be compiled to following which shows empty spaces around the number:
<?php if(1==1): ?> 1 <?php endif; ?>
Solution code would be compiled to this code:
<?php if(1==1): ?><?php echo e('1'); ?><?php endif; ?>
Which pretty much explains why this won't make additional spaces.
Did a bit more research and it looks like there is no solution as there is no spaceless tag in blade. I found a solution from someone who wrapping his string in extra hml tags (so that is easy as he ads spaces before and after the tag and the string inside tag si spaceless) but in my case I just need a string no spaces before and after ... I will go the old fashion php way ...
Try this:
#if(...) {{ 'abc' }} #else
I've run into similar problems with spaces.
A workaround I use is this:
Put your if statement into php tags
#php
$myVar = 'abc';
if(...) $myVar = 'cde';
#endphp
and then echo the defined variable
{{$myVar}}
It's a workaround, but I still think we always should remember that it's a PHP environment...
So, simply:
#php
if(...) echo "abc";
else echo "cde";
#endphp
I have found the solution in case there is space issue between #if()#endif and #if.
I have replaced the #if() #endif with the {{$wardname}} variable to be printed using {{$wardname}}#if and its removed conflict with #endif & #if
and applied logic like:
if($city->wardname!="") {
$wardname = "(".$city->wardname.")";
}else{
$wardname = "";
}
Implemented it as:
{{$wardname}}#if
The correct syntax is:
#if(...)
abc
#else
cde
#endif
I never saw unwanted spaces with this one.
Can someone explain to me why we use this instruction {notification} in the code of phpfox? For example in this code we use {notification}:
{if Phpfox::isUser() && !Phpfox::getUserBy('profile_page_id')}
getFullControllerName() == 'appletjava.index'} style="float: right;position: absolute;right: 199px;top: 7px;left:auto;" {/if}>
{notification}
{/if}
We can found other keywords also that use {} I want to know what it means.
all the {something} in phpfox templates get replaced for php code at "compilation" time. To learn what all the possibilities and replacements are open the file /include/library/phpfox/template/cache.class.php
For this specific question you will find it in line 1261 and it gets replaced for:
return '<?php Phpfox::getBlock(\'core.template-notification\'); ?>';
I have an array that have duplicated values, I want to print the value only once no matter how many time it exist on the array.
This is the code that I have:
{foreach item="item" from=$root.page.news.item }
{foreach from=$item.Tags item=tagitem key=kex}
{$tagitem}
{/foreach}
{/foreach}
This is what it prints right:
kim000kardashian
kim000kardashian
miley000cyrus
miley000cyrus
kim000kardashian
irina000shayk
and this is what I am looking to print
kim000kardashian
miley000cyrus
irina000shayk
Is there a way to achieve this only using Smarty Templates? or any way that I can use on the .tpl files?
Thanks in advance
{foreach item="item" from=$root.page.news.item }
{foreach from=$item.Tags item=tagitem key=kex}
{if !$done.$tagitem}
{$done.$tagitem = 1}
{$tagitem}
{/if}
{/foreach}
{/foreach}
I am not sure it works with all the versions.
Maybe it would be a bit cleaner to call an array_unique() in the php.
I have this smarty code :
{iterate from=fruits item=fruit}
....
{/iterate}
I want to have a counter inside this loop that accept a start value and increase by one until the loop continues.
I should i use? i am not good in smarty.
Thank you.
You can use the .iteration
{foreach from=fruits item=fruit}
current item #: {$smarty.foreach.fruits.iteration}
{/foreach}
source: http://www.smarty.net/docsv2/en/language.function.foreach.tpl#foreach.property.index
In case you have something like this:
{foreach from=$fruits item=fruit} {/foreach}
Instead of this:
{foreach from=fruits item=fruit} {/foreach}
You should use this syntax:
{foreach from=$fruits item=fruit name=counter}
Iteration no {$smarty.foreach.counter.iteration}
{/foreach}
I have an array in my template files ($data) witch looks like this
$data.1.name
$data.1.date
$data.1.place
$data.2.name
$data.2.date
$data.2.place
$data.3.name
$data.3.date
$data.3.place
now I would like to check the entire array and remove an item where the date is older then today.
The date check i figured out but i'm stuck at removing the item.
So let's say item 2 is older, the result should look like
$data.1.name
$data.1.date
$data.1.place
$data.3.name
$data.3.date
$data.3.place
Anyone an idea how i do this? If it is at all possible?
{foreach from=$data item=val}
{if $val.date >= $smarty.now}
{$val.name}
{$val.date}
{$val.place}
{/if}
{/foreach}