Creating a User Configurable Custom View
Additional control over a specific module view can be managed by creating view configurations providing options to the user which can be referenced in that view.
Inside the modulename/views/modulename folder resides the view templates for that module. And in most modules you'll also find a 'configure' folder which contains module specific 'Configuration Settings' tabs (views) displayed when selecting that module menu item.
The .tpl/template views in the 'configure' folder are for module-wide settings. We can create a view specific tab and settings by creating a 'viewname.config' file within the 'configure' folder.
In this example, we want to add some options to the new text module showall action view we created earlier titled 'showall_hint.tpl'. We'll give the user (admin or editor) an option of setting the border and background colors by adding a tab to the 'Configuration Settings' when the 'Hint' view is active.
Therefore, in the theme folder, you should've already created a folder named 'modules' and inside it a folder named 'text', and inside it a folder named 'views', and inside it a folder named 'text'. Inside hat folder, create a folder named 'configure'. And in that folder, create a file named 'showall_hint.config'. This is the 'config' template for the 'hint' view of the 'showall' action of the text module. We'll add two text controls that allow us to enter/edit the border
and background
settings. Enter the following text into that file and save it:
{* * Copyright (c) 2007-2011 OIC Group, Inc. * Written and Designed by Adam Kessler * * This file is part of Exponent * * Exponent is free software; you can redistribute * it and/or modify it under the terms of the GNU * General Public License as published by the Free * Software Foundation; either version 2 of the * License, or (at your option) any later version. * * GPL: http://www.gnu.org/licenses/gpl.txt * *} <h3>Hint View Settings</h3> {control type=text name="border" label="Border Color" value=$config.border|default:333333 size="10"} {control type=text name="background" label="Background Color" value=$config.background|default:DDDD66 size="10"}
Next edit the custom 'showall_hint.tpl' file to take advantage of these settings by referencing the $config.border
and $config.background
variables: Replace line 17:
<div class="module text showall" style="border: solid 3px #333333; background-color: #DDDD66; padding: 10px;">
with
<div class="module text showall" style="border: solid 3px #{$config.border|default:333333}; background-color: #{$config.background|default:DDDD66}; padding: 10px;">
Now on the text module with the 'Show All' action and the Hint view, if you select the 'Configuration Settings' module menu item, you'll see an additonal tab named 'Hint View Configuration' with the default settings for our two variables. You may notice from the code above we placed a 'default' modifier in the view template to use our original colors if not custom settings are saved, and we also used it in the view configuration template to fill in our default values if none are set.