Ad

How To Attach Several Images To Theme Settings?

- 1 answer

I trying to make attachMany file relation in theme Settings section of October CMS. In my own plugin i wrote

use Cms\Classes\Theme;
use Cms\Models\ThemeData;
use System\Classes\PluginBase;
use System\Models\File;

class Plugin extends PluginBase
{
    public function boot()
    {
        ThemeData::extend(function($model){
            $model->attachMany = [ "images" => File::class ];
        });
    }

    public function registerComponents()
    {
    }

    public function registerSettings()
    {
    }
}

And in theme.yaml of my theme

form:
    fields:
        images:
            label: images
            mode: image
            useCaption: true
            imageWidth: '100'
            thumbOptions:
                mode: crop
                extension: auto
            span: auto
            type: fileupload

So in Backend->Settings->CMS->Front-end Theme appeared new button "Customize" and my field images inside. But when i choose Upload I can select only one file!

So it works like attachOne instead of attachMany. Seems like the boot() method of Plugin doesn't work at all.

What am I doing wrong?

Ad

Answer

Use repeater.

fields:
    imagesq:
        type: repeater
        prompt: 'Add image'
        form:
            fields:
                image:
                    label: Image
                    type: mediafinder
                    mode: image
        tab: General

usage:

{% for img in this.theme.imagesq  %}                
     <li>{{ img.image }}</li>         
{% endfor %}
Ad
source: stackoverflow.com
Ad