This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hello! Sorry for the frequent questions, I'm learning :) I hope my questions and answers for them will help other :)
I know that you can easily create custom variables in static pages, such as:
{variable name="field_name" label="Field Label" tab="Tab Name" type="text"} {/variable}
But I want to create variables in new tabs in regular Pages (CMS-Pages). Is it possible to do that?
I've previously learned how to make custom variables for a theme: https://octobercms.com/docs/backend/forms
You can add this to the boot() method of your plugin:
Event::listen('backend.form.extendFields', function ($widget) {
if (!($widget->getController() instanceof CmsIndex && $widget->model instanceof CmsPage)) {
return;
}
$widget->addTabFields([
'settings[featured_image]' => [
'span' => 'storm',
'label' => 'Featured Image',
'type' => 'mediafinder',
'mode' => 'image',
'tab' => 'Images',
'imageWidth' => '400',
],
'settings[myVariable]' => [
'label' => 'My custom CMS page variable',
'type' => 'text',
'tab' => 'cms::lang.editor.settings',
],
]);
});
mjauvin said:
You can add this to the boot() method of your plugin:
Event::listen('backend.form.extendFields', function ($widget) { if (!($widget->getController() instanceof CmsIndex && $widget->model instanceof CmsPage)) { return; } $widget->addTabFields([ 'settings[featured_image]' => [ 'span' => 'storm', 'label' => 'Featured Image', 'type' => 'mediafinder', 'mode' => 'image', 'tab' => 'Images', 'imageWidth' => '400', ], 'settings[myVariable]' => [ 'label' => 'My custom CMS page variable', 'type' => 'text', 'tab' => 'cms::lang.editor.settings', ], ]); });
Thank you! I'll try.
Do I understand correctly that the sequence is this:
1) Create a new plugin with this code.
2) Use a plugin in layouts? Or use on the Page?
Last updated
1-4 of 4