XenOption Array Conditionals

nrep

Well-known member
I'm continuing to learn how XenForo works and my template modification is coming together, however I'm confused as to why this doesn't work:

Code:
<xen:if is="in_array({$forum.node_id}, array({xen:raw $xenOptions.articleforumids}))">

$xenOptions.articleforumids is set to "1,2,3" as a string on the options page.

I've tried changing the "articleforumids" data type to an array rather than string, but I get an error about allowing single selections and sub-options. However, surely as I'm using array{xen:raw} then I can just use a string anyway?
 
You will need to store the options as a serialized array or convert it before sending it to the template. array("1,2,3"); != array(1,2,3);.

Options are stored as a string.
 
Thanks for the reply - unfortunately my programming experience is extremely limited. I'm fine with making basic template modiciations, but I don't understand your answer fully.

Is this something I can make a basic change to the conditional (or use some sort of xen helper) to put the string into an array? I'm trying to do everything within templates and the options page (so far, so good).
 
Create an array with the following structure:

Code:
array
   [0] => 1
   [1] => 2
   [2} => 3

And the in_array command should work within the template.
 
I created a new option (disablePollCreation) that will contain a comma delimited numbers (ie forum IDs)

In my thread_create template I have the following (note the negation)
Code:
<xen:if is="!in_array({$forum.node_id}, array({xen:raw $xenOptions.disablePollCreation}))">

.....

</xen:if>

disablePollCreation contains 15,16,17

If I am in node 15, it works
If I go to node 16, it does note work
 
I didn't use this method in the end, I just opted for using forum parentids instead, as this was a way round it. I'd also be interested in getting this working so that I can use it in future.
 
Back
Top Bottom