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}
Related
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 a matrix field with several columns. When user submits the form I want to display only column fields user entered.
How can I check if matrix field is empty?
Just to clarify I'm talking about expressionengine's Matrix extension.
For example this wont work for me since the row can be submitted empty:
{if "{exercise_set1:total_rows}" >= 1}
{exercise_set1:table cellspacing="0" cellpadding="0" class="format_head"}
{/if}
To check if there are any rows filled use
{if your_matrixfield:total_rows>0}
{your_matrixfield}
Do your thing
{/your_matrixfield}
{/if}
I had the problem that users could attachs files to an entry but when no files were attached do not generate the Gallery
You just want to check to see if anything is set?
{matrix_tagpair}
{if column_var}{column_var}{/if}
OR
{if column_var != ""}{column_var}{/if}
{/matrix_tagpair}
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}
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
*}
I'hv got a problem when I am using foreach in smarty,
an array with 2 item was loop in a foreach, but the result is it loop 3 time.
I use doctrine to get a list of review by a user from database
Doctrine_Core::getTable('review')->findByUser($userId);
then I assign it to smarty and loop in foreach:
{foreach from=$reviewList item=review}
<p>User {$review.User.name} said: {$review.content}</p>
{/foreach}
However the result is e.g.:
User Joe said: yoyo
User Mary said: hihi
User said:
Please notice that the extra row doesn't get anything from the array.
I have checked that there is only 2 record in database, and I have count the $reviewList by count($reviewList), the result is also 2.
When I insert one more record to database, the forloop also loop extra one time.
Can anyone tell me why this happen? Thanks a lot!
This should filter the empty line:
{foreach from=$reviewList item=review}{if $review.User.name}
<p>User {$review.User.name} said: {$review.content}</p>
{/if}{/foreach}