Theme Global Settings

Hi,

I was just wondering if it’s possible (or if there is a specific way) to add theme specific settings to the ContentBox Admin.

For example I have a theme and want the user (content editor, admin etc) to be able to select the theme colour in the admin under System > Settings > Theme

So in the theme’s .cfc maybe there could be a this.settings structure which the admin would then interpret and display as a form like the other configuration options.

I understand these settings could be added manually via the Geek Settings but it would be nice if the could be automated depending on the theme and exposed within the site settings so users don’t have to go to the Geek settings.

Any thought’s would be welcome.

Richard McKenna

Richard this is a great idea and something i do want to add as well. In the next release 1.1 we alteady have lifecycle events for layouts for activation and deactivation.

The next step was to add settings.

What is yiur ideal feature for this?

Richard,

I have approached this in another manner, the concept is either the settings are stored in its own table for the theme, module or whatever and when it is loaded it checks to see if that exists if not it creates the default settings.

However there is a known issue with ContenBox at the moment, that when you delete themes and modules, the settings will never get deleted, until modules for ContentBox support an onDelete interception point.

But the concept is simple, and I am more than happy to show you what I am currently working on. In fact I might even blog this one.

I’d love to see what you have come up with.

My initial idea was to leverage the existing settings service and maybe prepend the layout name to the settings in order to identify the settings that relate to that theme.

I see from the current build as Luis mentioned the onActivation() and onDeactivation() methods are called if they exist. So I assume custom settings and their defaults could easily be stored in the db via the settingsService within these methods by injecting settingService@cb into the themes cfc. Maybe automatically prepending the setting name with “theme_” so the settings can be identified by System > Settings > Theme to generate a form for easy editing.

Not sure if this would be the best route to take as I’m still learning how ColdBox works, but it’s good stuff :slight_smile: No been this excited about coding in a long while.

Richard

Yes the life cycle events are for that purpose.

I guess my question is, if the layout cfc supports settings. Where in the ui would you manage them?

System - settings
Or
Look & feel - layout settings
Or
Look & feel - layouts - manage layout
Or
System - layout settings

Where would this go?

I am thinking of allowing a this.settings in the layout.cfc.

This.settings = [
{ name, type, required, default-value, options }
]

Then we would load and store the settings for you: layout_name_{setting}

Then create the form for you as well. The question is where?

Personally I think

System - Settings - Theme

seems the most natural place to put them. Maybe with a direct link from the layouts page. The this.settings structure would be ideal.

On side note to this just a little suggestion. Can the menu name “Look & Feel - Layouts” be changed to “Look & Feel - Themes”. It’s a bit confusing as Themes can have multiple layouts and the page title is “Layout Themes”

Richard

I would do this as a button next the layout you wanted to add the setting to and have it open in a lightbox.

I wrote 2 blogs on this the last few days, if you have any questions please let me know.

Ok guys I got inspired in the plane and have it working now. Will commit soon.

You will be able to declare settings in the layout cfc and ContentBox will register them and manage them for you. If the layout is deleted the settings are deleted as well.

The ui for the layouts has completely changed. I added a better tab navigator so you can manage the active layout and the other layouts.

The active layout now shows its information and the settings form.

Git FTW

Ok, this has been committed.

Can you try it out please!

Settings

You can declare settings for your layouts that ContentBox will manage for you.

this.settings = []

The value is an array of structures with the following keys:

  • name : The name of the setting (required), the setting is saved as cb_layoutname_settingName

  • defaultValue : The default value of the setting (required)

  • required : Whether the setting is required or not. Defaults to false

  • type : The type of the HTMl control (text=default, textarea, boolean, select)

  • label : The HTML label of the control (defaults to name)

  • title : The HTML title of the control (defaults to empty string)

  • options : The select box options. Can be a list or array of values or an array of name-value pair structures

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Anybody tried this yet?

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

signature0.jpg

Yeah was just about to post. You beat me to it :stuck_out_tongue:

Great stuff it works really well.

So as far as using the settings in the layouts is this the best way

#cb.setting(“cb_layout_corporattica_background_colour”)#

It did work, so I assume it’s all good.

Thanks for sorting this so quickly.

Richard

Yep, that looks good! Easy hugh?

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano