<p>If your first attempt – using a variable method – failed, it was probably because you had the "path" to that variable method wrong. If your variable method is called <code>getOptions()</code> and resides in a variable class called <code>MyPluginVariable</code>, the path should be</p>

<pre><code>craft.myPlugin.getOptions
</code></pre>

<p>not</p>

<pre><code>craft.myPlugin.settings.getOptions
</code></pre>

<p>Anyway, your current solution is fine. The ideal, "Craft-y" way to do stuff like this would probably be to keep the input options in a <a href="https://craftcms.stackexchange.com/questions/1998/how-does-a-plugin-include-its-own-config-options">plugin config file</a> and use a service + variable method to expose the data to the template – but for such a simple case there's really no need to over-engineer things. If you have more fields/options later, or need the data to be dynamic or stored in a database, deal with it then. <em>Don't optimize too early.</em></p>

<p>Personally, I'd consider just hard coding the options in the template:</p>

<pre><code>forms.selectField({
    'label': "myLabel",
    'instructions': "My Instructions"|t,
    'required': true,
    'id': 'myInput',
    'name': 'myInput',
    'options': {
        '' : 'Select',
        1 : '1',
        2 : '2',
        ...
    }
})
</code></pre>

CC BY-SA 3.0
2015-04-05T00:50:57.983Z
Thank you. As always, your time is appreciated. I wanted to just hard-code the values right in the file - just never had the right syntax I guess.
Damon
CC BY-SA 3.0
2015-04-06T19:07:35.320Z
No problem. Hard coding in the template would probably be my choice here, as well :)
Mats Mikkel Rummelhoff
CC BY-SA 3.0
2015-04-04T20:56:23.740Z
2015-04-04T20:56:23.740Z
2017-04-13T12:50:59.930Z
Mats Mikkel Rummelhoff
<p>I am attempting to populate a select input on my settings page for a plugin I am working on.</p>

<p><strong>_settings.html</strong></p>

<pre><code>forms.selectField({
    'label': "myLabel",
    'instructions': "My Instructions"|t,
    'required': true,
    'id': 'myInput',
    'name': 'myInput',
    'options': craft.myPlugin.settings.getOptions
})
</code></pre>

<p>I am getting the select to render, but it's just not getting any values.</p>

<p><code>craft.myPlugin.settings.getOptions</code> links to my variable file for my plugin.</p>

<p><strong>MyPluginVariable.php</strong></p>

<pre><code>public function getOptions()
{
    error_log(__FUNCTION__);  // Never gets executed
}
</code></pre>

<p>I thought maybe I could just return a name|value array in my getOptions method. </p>

<pre><code>return array('one'=&gt;'one', 'two' =&gt;'two');
</code></pre>

<p>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.</p>

<p>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.</p>

<p>Thank you!</p>

<p><strong>EDIT</strong></p>

<p>Well, I <em>may</em> have a solution, i'm curious if there is a better way though.</p>

<p><strong>MyPlugin.php</strong></p>

<pre><code>public function getSettingsHtml()
{
    $options = array(
        '' =&gt; 'Select',
        '1' =&gt; '1',
        '2' =&gt; '2',
        '3' =&gt; '3',
        '4' =&gt; '4',
        '5' =&gt; '5',
        '6' =&gt; '6',
        '7' =&gt; '7',
        '8' =&gt; '8',
    );

    return craft()-&gt;templates-&gt;render( 'myPlugin/_settings', array(
            'settings' =&gt; $this-&gt;getSettings(),
            'options' =&gt; $options
        ) );
    }
</code></pre>

<p><strong>_settings.html</strong></p>

<pre><code>forms.selectField({
    'label': "myLabel",
    'instructions': "My Instructions"|t,
    'required': true,
    'id': 'myInput',
    'name': 'myInput',
    'options': options
})
</code></pre>

<plugin-development>
Populate select input via static values on plugin settings page
# Populate select input via static values on plugin settings page

(Asked by: username_0 on 2015-04-03)

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
})

**Tags:** plugin-development


---

## 1 answers

### Answer by username_1 on 2015-04-04. Score: 2 | Accepted answer

If your first attempt – using a variable method – failed, it was probably because you had the "path" to that variable method wrong. If your variable method is called getOptions() and resides in a variable class called MyPluginVariable, the path should be
craft.myPlugin.getOptions

not
craft.myPlugin.settings.getOptions

Anyway, your current solution is fine. The ideal, "Craft-y" way to do stuff like this would probably be to keep the input options in a plugin config file and use a service + variable method to expose the data to the template – but for such a simple case there's really no need to over-engineer things. If you have more fields/options later, or need the data to be dynamic or stored in a database, deal with it then. Don't optimize too early.
Personally, I'd consider just hard coding the options in the template:
forms.selectField({
    'label': "myLabel",
    'instructions': "My Instructions"|t,
    'required': true,
    'id': 'myInput',
    'name': 'myInput',
    'options': {
        '' : 'Select',
        1 : '1',
        2 : '2',
        ...
    }
})

> **Comments:**
> **username_0**: Thank you. As always, your time is appreciated. I wanted to just hard-code the values right in the file - just never had the right syntax I guess.  
> **username_1**: No problem. Hard coding in the template would probably be my choice here, as well :)  

---

