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

Check if variable exists before conditional

Discussion in 'XenForo Development Discussions' started by nrep, Jan 10, 2014.

  1. nrep

    nrep Well-Known Member

    I've got a conditional statement which appears to throw up some errors in debug mode, which I'd like to fix:

    <xen:if is="!in_array({$forum.node_id}, {$xenOptions.threadtt_nodes})">

    1.in_array() expects parameter 2 to be array, null given in \library\XenForo\Template\Abstract.php(265) : eval()'d code, line 1409: 1408: ';
    1409: if (!in_array($forum['node_id'], $xenOptions['threadtt_nodes']))
    1410: {
    This problem appears because $xenOptions['threadtt_nodes'] isn't set at the moment. Is there a way around this error by modifying the conditional? I don't want to have to change the template code if a variable is/isn't set.

    BTW, I'm aware this may appear like a strange request given that this is a xenOptions variable - but I'm interested to see if there's a way to avoid the error appearing if a variable doesn't exist yet.
  2. Chris D

    Chris D XenForo Developer Staff Member

    <xen:if is="{$xenOptions.threadtt_nodes} AND !in_array({$forum.node_id}, {$xenOptions.threadtt_nodes})">
  3. nrep

    nrep Well-Known Member

    Thanks Chris - I tried that but it didn't work unfortunately. It may be to do with the other conditionals I have alongside it, so I'll try simplifying them and trying again - as I would have thought it should have worked.
  4. xf_phantom

    xf_phantom Well-Known Member

    What does the array in $xenOptions.threadtt_nodes look like?
    Because if it's not an array, or if it includes own keys (and not the node ids) it won't work too:D
    Last edited: Jan 10, 2014
  5. Chris D

    Chris D XenForo Developer Staff Member


    <xen:if is="is_array({$xenOptions.threadtt_nodes}) AND !in_array({$forum.node_id}, {$xenOptions.threadtt_nodes})">
  6. nrep

    nrep Well-Known Member

    Still no luck, but thanks for the replies - I'm going to attempt this by modifying the addon in a different way to see if I can fix it.

Share This Page