Check if variable exists before conditional

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})">

Code:
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.
 
<xen:if is="{$xenOptions.threadtt_nodes} AND !in_array({$forum.node_id}, {$xenOptions.threadtt_nodes})">
 
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.
 
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:
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.
Try:

<xen:if is="is_array({$xenOptions.threadtt_nodes}) AND !in_array({$forum.node_id}, {$xenOptions.threadtt_nodes})">
 
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.
 
Top Bottom