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

t.filteau30364
t.filteau30364

Okay, so I'm currently working on a website using October CMS. My goal is to have the site ultimately be as client-friendly as possible. As such, I'm using the static page plugin while creating layouts with placeholders that will be editable via the admin interface.

The thing is that I now have three pages with the exact same layout, but a different color-scheme (red, yellow and green to be exact). What I'd like to do is allow the user to change the color-scheme via the admin interface without having to edit a file manually. That way, if my client wants to add a page to his website later on, he can choose the layout and just pick the color that he wants straight from the static-page admin section. The problem is that said admin section has no place for custom parameters, so I'm rather stuck.

Of course, I could just create three different layouts, one for each color... but that feels kind of silly. There has to be a way to give layouts some sort of custom parameters without having to rely on programming.

Anyone has any idea?

BG78
BG78

Hi. I extended the static pages in register method of a Plugin.

public function register() 
{
    Event::listen('backend.form.extendFields', function($widget) {
        if ($widget->model instanceof \Rainlab\Pages\Classes\Page) {
            $widget->addTabFields([
                [your fielddefinitions -> color scheme dropdown]
            ], 'primary');
        }
    }
}

I dont know if its a perfect solution, but for me it works fine.

t.filteau30364
t.filteau30364

Thanks a lot BG78. I now have the property successfully displayed on my settings page. Here's what I have:

        Event::listen('backend.form.extendFields', function($widget) {

        // Only for the User model
        if (!$widget->model instanceof \Rainlab\Pages\Classes\Page) {
            return;
        }

        if($widget->model->viewBag['layout'] != "design")
            return;

        // Add an extra birthday field
        $widget->addTabFields([
            'colorscheme' => [
                'label'   => 'Color scheme',
                'type'    => 'dropdown',
                'options' => ['1' => 'Rouge', '2' => 'Jaune', '3' => 'Vert'],
                'tab'     => 'cms::lang.editor.settings'

            ]
        ]);
    });

The problem is that now, I don't know what to do with this property. How do I access it front-end?

BG78
BG78

You should use it as variable {{colorscheme}} in frontend. If this will not work, try to define your field as

'viewBag[colorscheme]' => [

t.filteau30364
t.filteau30364

Ok, so it doesn't work... but I think the problem is that the property's value isn't saved anywhere. For example, if I go ahead and change the dropdown's value from "Rouge" to "Jaune" and then save the page. When I refresh the page, I'm back to "Rouge" as if nothing ever happened. Why is it that the value is not being saved... and of course, how do I make it so that it does persist?

t.filteau30364
t.filteau30364

OK, nevermind my last post, you were right, the viewbag[colorscheme] actually worked. What threw me off is that there is no quotes surrounding the "colorscheme" word.

'viewBag["colorscheme"]' => ... // This is WRONG
'viewBag[colorscheme]' => ... // This is RIGHT

Thanks a lot for your help :).

1-6 of 6

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