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

XenOption inside of ismemberof conditional?

Discussion in 'XenForo Questions and Support' started by IFeelYourPain13, Jan 13, 2012.

  1. IFeelYourPain13

    IFeelYourPain13 Active Member

    Im trying to get a variable inside of another variable to work. Any ideas?
    Code:
    <xen:if is="{xen:helper ismemberof, $visitor, {$xenOptions.permissions}}">
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  3. IFeelYourPain13

    IFeelYourPain13 Active Member

    I know the code is valid, but it only works for one usergroup. Multiple will not work. 1,2,3 1, 2, 3 for example.
     
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Multiple groups must be specified like this:

    http://xenforo.com/community/threads/usergroup-checking-in-the-templates.9447/#post-282874

    A variable like {$xenOptions.permissions} can only represent one group, not multiple. Multiple groups must be separate parameters. To clarify, these two are very different:

    Code:
    <xen:if is="{xen:helper ismemberof, $visitor, 2, 3, 4}">
    
    Code:
    <xen:if is="{xen:helper ismemberof, $visitor, '2,3,4'}">
    
    I suspect you might be attempting the latter by way of {$xenOptions.permissions} which does not work. Each group must be a separate parameter. You can't use a single string parameter to specify multiple groups.
     
  5. IFeelYourPain13

    IFeelYourPain13 Active Member

    <xen:if is="{xen:helper ismemberof, $visitor, {$xenOptions.permissions}}">
    I have $xenOptions.permissions set to 1, 2, 3 but it is not working. What could I do to get it to recognize it altogether instead of just the 1st character?
     
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Per my previous post, that won't work. The string of group ids needs to be split up.

    I just posted a suggestion about this:

    http://xenforo.com/community/threads/ismemberof-mixed-type.25933/
     
  7. IFeelYourPain13

    IFeelYourPain13 Active Member

    Ok so currently no way to do it?

    I remember in vB you could run an explode query.
     
  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    vB has never allowed explode() in template syntax. But it does allow an array of ids to be used in this circumstance, unlike XF. That's what my suggestion is about.
     
  9. IFeelYourPain13

    IFeelYourPain13 Active Member

    Not template. PHP code. In my old modification I used explode for permissions.
     
  10. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Absolutely you can use explode() in PHP. But we are working with template syntax. You can write an addon to do your group checking using PHP code instead of template code.
     
  11. IFeelYourPain13

    IFeelYourPain13 Active Member

    But unlike vb I used the variable I set up with the explode to be referred back to in template.
    <php>
    $usergroups = explode();
    </php>

    <xen:if is="{xen:helper ismemberof, $visitor, $usergroups}">
     
  12. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    That works in vB (passing an array of group ids), but not in XF. That is what my suggestion is about.
     
  13. IFeelYourPain13

    IFeelYourPain13 Active Member

    Im just not use to the whole requiring a listener. Im use to just putting the code that I need in the xml. How would I go about the permission for the mod without the passing of arrays?
     
  14. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  15. IFeelYourPain13

    IFeelYourPain13 Active Member

    I assume this cant be used in templates can it...
     
  16. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Nope. That is for use in the PHP code, such as in listeners.
     

Share This Page