Alexander Guskov
Alexander Guskov

Reputation: 421

How to attach several images to theme settings?

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?

Upvotes: 0

Views: 159

Answers (1)

Iva Sidor
Iva Sidor

Reputation: 26

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

Upvotes: 1

Related Questions