• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.5 How do I determine the size of an array in a template?

Stuart Wright

Well-known member
#1
I have a review with no Pros or Cons
https://www.avforums.com/review/datawind-ubisurfer-review.153#sectionAnchor24933
and the template is supposed to only display the Pros and Cons if there are any.
Code:
<xen:if is="{$content.pros} AND {$content.cons}">
yet the Pros and Cons are displayed resulting in the display of the headers and nothing else.
Should I change the conditional to test for the number of elements in the arrays?
 
Last edited:

Brogan

XenForo moderator
Staff member
#2
You can dump it to see what it contains.
HTML:
{xen:helper dump, $content.pros}
You may need to use an exclusive condition or value rather than just checking for the presence of the param.
 

Brogan

XenForo moderator
Staff member
#4
Yes, as it's not NULL, it's meeting the terms of the condition.

You can likely just edit the condition to add > 0 for both, although that would require both to be > 0 in order for that to evaluate.
 

Chris D

XenForo developer
Staff member
#5
Ideally the back end code would be handling that specifically. The easiest way to do that is just run the array through array_filter (with no function argument) before it is saved and it will automatically strip out entries from the array which are "falsey".
 
Last edited: