Theme Development - Theme Options

Permalink
Hey,

Wondering if you guys got any idea how to create a "Theme Options" page similar to the one that c5hub did with their Fundamental theme ( See here:http://fundamental.c5hub.com/features/theme-options... )

Would like to further improve my C5 Theme development with something like that. Didn't find any documentation about it so decided to ask you guys.

Any help is appreciated.

Best Regards,
David

PSDAddict
 
rge replied on at Permalink Reply
I am not sure how they did it exactly. They registered a single page from within their package. For this check the documentation.

When the form is submitted the data is received in the controller action method. The information than can be stored in a Config object.

for example:
public function submit()
{
   $data = $this->post();
   $errors = $this->validate($data);
   $this->error = $errors;
   //save the data 
   if(!$errors->has()){
      Config::save('nav.linkAlignment', $data['linkAlignment']);
      Config::save('nav.brandingEnabled', $data['brandingEnabled']);
   }
}


later in the theme or controller they can check the config settings
if( Config::get('nav.brandingEnabled') ){
//do something
}


For creating a package you can read the documentation. The config part is not in there.
WebcentricLtd replied on at Permalink Reply
I've done a very similar thing and RGE is spot on for the way I did it.
Config::save.... ends up writing the values you pass into the nodes you specify in
/application/config/generated_overrides/concrete.php

below is a sample from options I have added:

'theme_options' => array(
        'full_width' => true,
        'menu' => 'menu-3',
        'header' => 'header-1',
        'footer' => 'footer-3',
        'primary_font' => 'Roboto',
        'secondary_font' => 'Oswald',
        'tertiary_font' => 'open Sans'
    ),
    'title' => array(
        'visible' => true,
        'position' => 'left',
        'size' => 'small'
    ),


The good news is there is a shortcut - to test things out you don't need to build a package right away.

You can manually add config items to that file and access them in your theme like so:

$fullWidth = config::get('concrete.theme_options.full_width');
$title = Config::get('concrete.title');
$menu = Config::get('concrete.theme_options.menu');

For example I use $fullWidth to switch my theme quickly between a full screen layout or boxed layout.
PSDAddict replied on at Permalink Reply
PSDAddict
Appreciate the quick & detailed replies guys. Going to have a look at it now.