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

How to convert an admin option into an array?

Discussion in 'XenForo Development Discussions' started by 0ptima, Sep 6, 2013.

  1. 0ptima

    0ptima Well-Known Member

    Im trying to hide polls in certain forums and would like to configure which forums will not have polls in the Admin CP.

    I created a new option with a comma delimited value
    upload_2013-9-5_19-51-41.png

    In the thread_create template, I want to access this option, but I need it in an array format as the following will not work
    upload_2013-9-5_19-53-53.png

    How can I achieve this? Thanks.
     
  2. 0ptima

    0ptima Well-Known Member

    Anybody have any idea on how to achieve this?
     
  3. Jeremy

    Jeremy XenForo Moderator Staff Member

    If you do this, what does it print out:
    Code:
    {xen:helper dump, array({xen:raw $xenOptions.hidePolls})}
     
  4. 0ptima

    0ptima Well-Known Member

    This
    {xen:helper dump, $xenOptions}

    (got a syntax error with your code)

    printed
    ["zhidepolls"] => string(21) "s:14:"13,14,38,59,60""

    (Ive been fiddling with the option so its not quite the same as when I first posted.)
     
  5. Jeremy

    Jeremy XenForo Moderator Staff Member

    What's the data type for your option?
     
  6. 0ptima

    0ptima Well-Known Member

    String....
     
  7. 0ptima

    0ptima Well-Known Member

    If I change it to array, I get this error

    • Data Type:
      Please select a data type other than 'array' if you want to allow single selections only.
    • Array Sub-Options:
      Please enter a list of sub-options for this array.

    What is a sub-option?
     
  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    That is a string var. It doesn't eval like you are thinking. You can check individual values using PHP code (explode the string, process the individual array elements). If you are wanting to do this using template syntax then you need to explode the string in PHP, pass the resulting array to the template, then use in_array() on it.
     
  9. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Another (perhaps better) option is to change your option to be an array type instead of a string type.
     
  10. 0ptima

    0ptima Well-Known Member

    Where would I execute the PHP code?
     
  11. 0ptima

    0ptima Well-Known Member


    How would I do that?
     
  12. Jeremy

    Jeremy XenForo Moderator Staff Member

    You'd want to extend the controller for creating a thread to interject your split array into the view params.
     
  13. 0ptima

    0ptima Well-Known Member


    Would you have an example on how to do that?
     
  14. Jeremy

    Jeremy XenForo Moderator Staff Member

  15. 0ptima

    0ptima Well-Known Member

    Thanks for the link.
     
  16. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  17. 0ptima

    0ptima Well-Known Member

    Thanks Jake.
     

Share This Page