Option selected in Template and assign_block_vars

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
Slechtvalk
Registered User
Posts: 34
Joined: Tue Jan 15, 2008 12:56 pm

Option selected in Template and assign_block_vars

Post by Slechtvalk » Tue May 26, 2015 6:31 pm

I got a menu item on a custom page where i filter a sql query

the menu itself is a sql table

so i readout the menu and use template assign_block_vars to do a loop in the template....

this is part of my html template

Code: Select all

<select name='role' onchange='this.form.submit()'>
        <!-- BEGIN rolelist -->
        <option value='{rolelist.ROLE_ID}'
        <!-- IF rolelist.ROLE_ID = S_ROLE -->
        selected
        <!-- ENDIF -->
        >{rolelist.ROLE_NAME}</option>
        <!-- END rolelist -->
        </select>
S_ROLE is the request_var and put into $template

Is there an easier way to highlight the selected?
I hope you understand what you mean. Thank you!

Slechtvalk
Registered User
Posts: 34
Joined: Tue Jan 15, 2008 12:56 pm

Re: Option selected in Template and assign_block_vars

Post by Slechtvalk » Tue May 26, 2015 6:35 pm

god damn

Code: Select all

<option value='{rolelist.ROLE_ID}' <!-- IF rolelist.ROLE_ID == S_ROLE --> selected<!-- ENDIF -->>{rolelist.ROLE_NAME}</option>
this works, sorry and thank you

Slechtvalk
Registered User
Posts: 34
Joined: Tue Jan 15, 2008 12:56 pm

Re: Option selected in Template and assign_block_vars

Post by Slechtvalk » Tue May 26, 2015 8:25 pm

oh my, how can i do in nested block_vars?

within sql it cant be made, i think

Code: Select all

<!-- BEGIN smurfyadminlist -->
    <tr class="<!-- IF hangarliste.S_ROW_COUNT is even -->bg1<!-- ELSE -->bg2<!-- ENDIF -->">
        <td>{smurfyadminlist.MECH_NAME}</td>
        <td>{smurfyadminlist.MECH_MODELL}</td>
        <td>{smurfyadminlist.MECH_TONS}</td>
        <td>{smurfyadminlist.LOADOUT_ID}</td>
        <td><select name="{smurfyadminlist.LOADOUT_ID}.ROLE_ID"><!-- BEGIN smurfyroles --><!-- IF smurfyadminlist.CAT_ID == smurfyroles.ROLE_ID --><option value="{smurfyroles.ROLE_ID}" selected>{smurfyroles.ROLE_NAME}</option><!-- ELSE --><option value="{smurfyroles.ROLE_ID}">{smurfyroles.ROLE_NAME}</option><!-- ENDIF --><!-- END smurfyroles --></select></td>
        <td>{smurfyadminlist.NAME}</td>
        <td>{smurfyadminlist.LINK}</td>
        <td>{smurfyadminlist.ACTIVE}</td>
    </tr>
    <!-- END smurfyadminlist -->
smurfyadminlist and smurfyroles are different SQL queries. But to put it into an update/change form i need all options for ROLE_ID, not only the saved one of the database....

Wardormeur
Registered User
Posts: 142
Joined: Sun Jan 27, 2013 9:22 am

Re: Option selected in Template and assign_block_vars

Post by Wardormeur » Thu May 28, 2015 9:55 pm

Not quite sure i get the question, but isn't an array_merge (http://php.net/manual/fr/function.array-merge.php) what you're looking for? Merging selected to non_selected
In the case of an option list, just add the "selected" property to your list
for example :

Code: Select all

foreach($phpbb_selected_roles as $proles_id)
{
						if($proles_id == $local_phpbb_roles['ID'] ){
							$local_phpbb_roles['selected'] = 'selected';
		}
}
Edit : actually, this would be even better (http://php.net/manual/en/function.array ... t-ukey.php) : this is an array_merge with a callback function

Slechtvalk
Registered User
Posts: 34
Joined: Tue Jan 15, 2008 12:56 pm

Re: Option selected in Template and assign_block_vars

Post by Slechtvalk » Fri May 29, 2015 11:23 pm

Thank you, ill have an eye on that.

Post Reply

Return to “Extension Writers Discussion”