October CMS - extend page to have an associated image
Ad
What are the best and clean possible ways to extend functionality for including an associated image to each page object (CMS page or StaticPage), adding a corresponding upload widget to the page's configuration in the OctoberCMS backend?
(Additionally, and just as an aside: In what way can one add an associated image to a site's theme?)
Ad
Answer
Ad
For CMS pages, add a register() method to your Plugin.php file:
public function register()
{
Event::listen('backend.form.extendFields', function($widget) {
if (!$widget->model instanceof \Cms\Classes\Page) return;
$widget->addTabFields([
'settings[image_filet]' => [
'label' => 'Page image',
'tab' => 'Image',
'field' => 'settings[image_file]',
'type' => 'mediafinder',
'comment' => 'Image url is available via the page settings under the name of image_file'
],
], 'primary');
});
}
And the value is available via this.page.image_file Twig value
Ad
source: stackoverflow.com
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad