• 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> ?

Chris D

XenForo developer
Staff member
#2
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

Well-known member
#3
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:

Chris D

XenForo developer
Staff member
#4
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>
 

Liam W

Well-known member
#5
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>
I tried that, but the <option> tags were appearing after the </select> tag, resulting in no options...