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

Stuart Wright

Well-known member
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:
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.
 
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.
 
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:
Top Bottom