1. 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?

Discussion in 'Styling and Customization Questions' started by Stuart Wright, Nov 10, 2015.

  1. Stuart Wright

    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: Nov 10, 2015
  2. Brogan

    Brogan XenForo Moderator Staff Member

    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.
     
  3. Stuart Wright

    Stuart Wright Well-Known Member

    Thanks Paul, I'm getting
    I guess I need to test for that also.
     
  4. Brogan

    Brogan XenForo Moderator Staff Member

    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.
     
  5. Chris D

    Chris D XenForo Developer Staff Member

    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: Nov 10, 2015
    Brogan likes this.
  6. Stuart Wright

    Stuart Wright Well-Known Member

    Thanks, both.
     
  7. Stuart Wright

    Stuart Wright Well-Known Member

    This works
    and I have to assume that the first item of the array contains something.
     

Share This Page