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

How to use <xen:selectunit> ?

Discussion in 'XenForo Development Discussions' started by Liam W, Jul 7, 2013.

  1. Liam W

    Liam W Well-Known Member

    How do I add the options to xen:selectunit in an admin template?
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    It's all there in the existing code.

    The user_edit template has loads of examples.

    There's these:

    Code:
                    <xen:selectunit label="{xen:phrase user_state}:" name="user_state" value="{$user.user_state}">
                        <xen:option value="valid">{xen:phrase valid}</xen:option>
                        <xen:option value="email_confirm">{xen:phrase awaiting_email_confirmation}</xen:option>
                        <xen:option value="email_confirm_edit">{xen:phrase awaiting_email_confirmation_from_edit}</xen:option>
                        <xen:option value="moderated">{xen:phrase awaiting_approval}</xen:option>
                    </xen:selectunit>
    But there's also this type:

    Code:
                    <xen:checkboxunit label="{xen:phrase secondary_user_groups}:" name="secondary_group_ids" class="checkboxColumns">
                        <xen:options source="$secondaryGroups" />
                    </xen:checkboxunit>
    Where $secondaryGroups is an array passed to the template as a view parameter. It should be in this format:

    PHP:
    $secondaryGroups = array(
         
    'some_value' => array(
              
    'value' => 'some_value',
              
    'label' => new XenForo_Phrase('some_phrase')
         ),
         
    'some_other_value' => array(
              
    'value' => 'some_other_value',
              
    'label' => new XenForo_Phrase('some_other_phrase')
         )
    );
     
    Liam W likes this.
  3. Liam W

    Liam W Well-Known Member

    I tried using the first one (in a xen:foreach tag), but the select was being closed just before the options were printed.

    <xen:options> produces an error saying there isn't a tag called options...
     
    Last edited: Jul 7, 2013
  4. Chris D

    Chris D XenForo Developer Staff Member

    You wouldn't normally use a loop to create a select unit, but you could use a loop inside a select unit to render the options.
    Code:
                    <xen:selectunit label="{xen:phrase user_state}:" name="user_state" value="{$user.user_state}">
                        <xen:foreach loop="$options" key="$value" value="$text">
                             <xen:option value="{$value}">{$text}</xen:option>
                        </xen:foreach>
                    </xen:selectunit>
     
  5. Liam W

    Liam W Well-Known Member

    I tried that, but the <option> tags were appearing after the </select> tag, resulting in no options...
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    Then you were doing something wrong.

    If you provide the code you were using it will be easier to debug.
     
    Jeremy likes this.

Share This Page