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

XenOption Array Conditionals

Discussion in 'XenForo Development Discussions' started by nrep, Aug 18, 2013.

  1. nrep

    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:

    <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?
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    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.
    nrep likes this.
  3. nrep

    nrep Well-Known Member

    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).
  4. JulianD

    JulianD Well-Known Member

    Create an array with the following structure:

       [0] => 1
       [1] => 2
       [2} => 3
    And the in_array command should work within the template.
  5. 0ptima

    0ptima Well-Known Member

    Where would you do this?
  6. 0ptima

    0ptima Well-Known Member

    @nrep Did you get this to work? I want to do something similar.
  7. Jeremy

    Jeremy XenForo Moderator Staff Member

    What is the code you are attempting to use?
  8. 0ptima

    0ptima Well-Known Member

    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)
    <xen:if is="!in_array({$forum.node_id}, array({xen:raw $xenOptions.disablePollCreation}))">
    disablePollCreation contains 15,16,17

    If I am in node 15, it works
    If I go to node 16, it does note work
  9. nrep

    nrep Well-Known Member

    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.
  10. nrep

    nrep Well-Known Member

    Did anyone ever figure this out? I'd be really interested to know! :)

Share This Page