I have this array in PHP being passed to smarty:
unansweredTopics_arr
I want to create an if statement and if there is a count of more than 0 items, display the contents of the array by looping through it. If there are no items, I want to display some generic text like "No Topics Found".
Is there a way to count the items in an array via Smarty?
The best solution I can think of would be to use the smarty {php}{/php} tags and create a function to call like
function post_count($x){}
I don't know Smarty as well as I would like and still learning it. The best solution I can think of would be to use the smarty {php}{/php} tags and create a function to call like
[code]function post_count($x){ }[/code]
I don't know Smarty as well as I would like and still learning it. :)
With PHP 5.5 and Smarty 3 you can use new functions:
{
$type_count = array_count_values(array_column($mydata,'type'))
}
Count of type 2: {
$type_count['2']
}With PHP 5.5 and Smarty 3 you can use new functions:
{
$type_count = array_count_values(array_column($mydata,'type'))
}
Count of type 2: {
$type_count['2']
}
in smarty 2 or 3, personally I like rain TPL {function="count($my_array)"}As of smarty 3 you can use the following [code]{count($my_array)}
[/code] or you can use [code]{$my_array|count}[/code] in smarty 2 or 3, personally I like rain TPL {function="count($my_array)"}
smarty.incutio.com/?page=SmartyFrequentlyAskedQuestions#template-1
check this linksmarty.incutio.com/?page=SmartyFrequentlyAskedQuestions#template-1
check this link
jakemadness
I don't know Smarty as well as I would like and still learning it.
Are you sure you want to delete this post?