Giving a theme its own settings file
This page is for designers who want options in their theme (a color scheme, the number of teasers on the front page, Open Graph defaults) without asking users to edit templates.
A real example
cjw_themes_jumper ships settings/cjw_jumper.ini.append.php. Its 0.1.2 release, for example, reads the classes
treated as articles for Open Graph from cjw_jumper.ini [OpenGraph] ArticleClasses.
Step by step
Create
extension/mytheme/settings/mytheme.ini.append.phpwith a documented block:/* #?ini charset="utf-8"? [FrontPage] # How many teasers the front page shows (a whole number from 1 to 12) TeaserCount=6 */An installation without your theme has no
mytheme.iniat all, so the append file is the only place the defaults live. Comment every setting.Read it in a template with the
ezinioperator:{def $count = ezini( 'FrontPage', 'TeaserCount', 'mytheme.ini' )}See The ezini operator.
Read it in PHP (an operator or a module of the theme):
$count = (int) eZINI::instance( 'mytheme.ini' )->variable( 'FrontPage', 'TeaserCount' );Clear the INI cache and check:
php bin/php/ezcache.php --clear-tag=ini --allow-root-user ./console exp:ini where mytheme.ini/FrontPage/TeaserCount --allow-root-userTell users in the README how to override it: in
settings/override/mytheme.ini.append.php, never in the theme's own file (an update would overwrite it). A siteaccess folder does not work for a key the theme's file sets, because thesettings/of the extensions inActiveExtensions[]are read after the siteaccess settings and win.
Good practice
- Validate what you read: cast numbers, compare against a list of allowed values, fall back to the default.
- Never read secrets from a theme's settings file; secrets belong to the installation's override folder.
- When you rename or remove a setting, keep reading the old name for a while (Deprecating a setting or a template).
Related pages
- Settings files in an extension
- Change settings from the command line
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.