I am attempting to populate a select input on my settings page for a plugin I am working on.
_settings.html
forms.selectField({
'label': "myLabel",
'instructions': "My Instructions"|t,
'required': true,
'id': 'myInput',
'name': 'myInput',
'options': craft.myPlugin.settings.getOptions
})
I am getting the select to render, but it's just not getting any values.
craft.myPlugin.settings.getOptions links to my variable file for my plugin.
MyPluginVariable.php
public function getOptions()
{
error_log(__FUNCTION__); // Never gets executed
}
I thought maybe I could just return a name|value array in my getOptions method.
return array('one'=>'one', 'two' =>'two');
The value(s) that this select will have are literally that easy and will never change. That's why I was going this route vs. a db lookup.
I get errors that the value needs to be a string, so I know I can't just have an array right in the settings file. Not exactly sure where to go from here.
Thank you!
EDIT
Well, I may have a solution, i'm curious if there is a better way though.
MyPlugin.php
public function getSettingsHtml()
{
$options = array(
'' => 'Select',
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6',
'7' => '7',
'8' => '8',
);
return craft()->templates->render( 'myPlugin/_settings', array(
'settings' => $this->getSettings(),
'options' => $options
) );
}
_settings.html
forms.selectField({
'label': "myLabel",
'instructions': "My Instructions"|t,
'required': true,
'id': 'myInput',
'name': 'myInput',
'options': options
})