Liam W in memoriam 1998-2020 Jul 7, 2013 #1 How do I add the options to xen:selectunit in an admin template?
Chris D XenForo developer Staff member Jul 7, 2013 #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') ) );
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 in memoriam 1998-2020 Jul 7, 2013 #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: Jul 7, 2013
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...
Chris D XenForo developer Staff member Jul 7, 2013 #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>
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 in memoriam 1998-2020 Jul 7, 2013 #5 Chris Deeming said: 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> Click to expand... I tried that, but the <option> tags were appearing after the </select> tag, resulting in no options...
Chris Deeming said: 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> Click to expand... I tried that, but the <option> tags were appearing after the </select> tag, resulting in no options...
Chris D XenForo developer Staff member Jul 7, 2013 #6 Then you were doing something wrong. If you provide the code you were using it will be easier to debug.
Then you were doing something wrong. If you provide the code you were using it will be easier to debug.