This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

stom
stom

Hello,

I'm very new to October CMS and i'm currently building my first basic bootstrap theme. I have a working template with theme.yaml:

name: Bootstrap
description: 'Bootstrap Theme'
author: stom
homepage: domain.co.uk
require:
    - ToughDeveloper.ImageResizer
form: theme_fields.yaml

My theme_fields.yaml has several form fields in it. I would like to add a checkboxlist of possible CDN resources to append to the page and have created the following fields:

fields:
    include_from_cdn:
        label: Include from CDN:
        type: checkboxlist
        span: 'left'
        options:
            include_bootstrap_css: Bootstrap 4.3 CSS
            include_bootstrap_js: Bootstrap 4.3 JavaScript
            include_bootswatch_css: Bootswatch CSS (choose from dropdown)
            include_fontawesome_css: FontAwesome CSS
            include_jquery_css: jQuery Javascript
    cdn_bootswatch:
        label: Bootswatch theme to include (when using CDN)
        type: dropdown
        span: 'storm'
        trigger:
            action: show
            field: include_from_cdn[]
            condition: value[include_bootswatch_css]
        cssClass: 'col-xs-12 col-sm-6 clearfix'
        assetVar: use_local_bootswatch
        options:
            false: None (default)
            cerulean: Cerulean
            cosmo: Cosmo
            cyborg: Cyborg
            darkly: Darkly
            flatly: Flatly
            journal: Journal
            litera: Litera
            lumen: Lumen
            lux: Lux
            materia: Materia
            minty: Minty
            pulse: Pulse
            sandstone: Sandstone
            simplex: Simplex
            sketchy: Sketchy
            slate: Slate
            solar: Solar
            spacelab: Spacelab
            superhero: Superhero
            united: United
            yeti: Yeti

The problem I currently face is that when I try to save any combination of checked boxes I get the following error:

"Unexpected type of array when attempting to save attribute "include_from_cdn", try adding it to the $jsonable property." on line 737 of /media/sf_webshare/october.dev/vendor/october/rain/src/Database/Model.php

After reading the above error, and referring to [https://octobercms.com/docs/themes/development#customization](the documentation) I see that I must add the following code (with my own var name) to my theme:

\Cms\Models\ThemeData::extend(function ($model) { 
    $model->addJsonable('contact');
});

My question is where do I add that code? Not in the theme.yaml file I assume. I'm a bit lost at this point, I had kind of assumed October would have taken care of this automagically, but it seems I'll need to do some additional steps when using checkboxlists? If anyone can tell me where I should be adding this I'd be very grateful.

BG78
BG78

Hi. Create a simple new plugin and place your extend function inside the plugins boot() function in the plugin.php file.

public function boot() {
    \Cms\Models\ThemeData::extend(function ($model) { 
        $model->addJsonable('include_from_cdn');
    });
}

This works for me.

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.