Add settings to plugins cp section instead of settings page I've setup a plugin like so http://domain/admin/plugin-handle (cp section) and a settings page here http://domain/admin/settings/plugins/plugin-handle

I can edit my plugin settings under the latter URL, however I would like non admins to be able to do so as well, but under http://domain/admin/plugin-handle

How can I go about this? Adding e.g.

{{ forms.textField({
    label: 'Headline'|t('craft-terms-of-service'),
    instructions: 'Enter the headline of your TOS here.'|t('craft-terms-of-service'),
    id: 'tosHeadline',
    name: 'tosHeadline',
    value: settings['tosHeadline']})
}}


to the http://domain/admin/plugin-handle template (src/templates/index.twig) (cp section) non-admins have access to, I get Variable "settings" does not exist. I can't figure out how to make it accessible/exist.

Thanks in advance

Edit

Figured out how to add fields to the cp section through the "Getting Started with Craft Plugin Development" course on craftquest.io, however the way I'm saving the settings to the db is rather crude. I'm just doing Craft::$app-&gt;db-&gt;createCommand(.... to update the plugins table. It works, but I'm sure there are much more elegant ways of doing it?
Solution

In my src/template/index file I added this to make the form work

{% extends "_layouts/cp" %}
{% import "_includes/forms" as forms %}

&lt;form action="" method="post"&gt;
{{ csrfInput() }}

{{ forms.hidden({
    name: 'action',
    value: 'craft-terms-of-service/default/save-tos'
}) }}

{{ forms.hidden({
    name: 'tosCurrentVersion',
    value: now.timestamp
}) }}

{{ forms.lightswitchField({
    label: 'Enable TOS?'|t,
    id: 'tosEnabled',
    name: 'tosEnabled',
    on: craft.craftTermsOfService.get('tosEnabled'),
    first: true
}) }}

{{ forms.textField({
    label: 'Headline'|t('craft-terms-of-service'),
    instructions: 'Enter the headline of your TOS here.'|t('craft-terms-of-service'),
    id: 'tosHeadline',
    name: 'tosHeadline',
    value: craft.craftTermsOfService.get('tosHeadline')
}) }}

{{ craft.craftTermsOfService.redactorField({
    label: 'Terms of Service'|t('craft-terms-of-service'),
    instructions: 'Enter the TOS every user must accept before using the site below.'|t('craft-terms-of-service'),
    name: 'tosBody',
    rows: 4,
    value: craft.craftTermsOfService.get('tosBody')|raw
})|raw }}

&lt;input type="submit" class="submit btn" value="{{ 'Save'|t }}"&gt;




Using the actions/craft-terms-of-service/default/save-tos controller I took the data from the request and updated the data in the plugins table. Also in the form in my index template I used the craft.craftTermsOfService.get variable to fetch the settings from the plugins table and give each form element its appropriate value.

For details, see the controller on github and the variable on github. Note this is the first time I make a plugin, so it's probably a mess, sorry about that.