Lesson 3.1: Listing stylesheets and scripts in design.ini
In Exponential, stylesheets and scripts are not linked by hand in the pagelayout. They are named in lists in
design.ini, and the pagelayout asks the ezjscore packer to load the lists. A theme that follows this can be extended
by other extensions, packed into few files, and run under a Content Security Policy. This lesson sets up the lists of
training_theme.
At a glance
| Course | Theme design |
| Module | Module 3: Stylesheets and scripts through the packer |
| Duration | 45 minutes (15 presenting, 30 exercise) |
| Level | Beginner |
| Audience | Designers and front-end developers |
| Prerequisites | Module 2: training_theme with a skip link and a breadcrumb |
Learning objectives
After this lesson, learners can:
- name the stylesheet and script lists of
design.iniand which designs read which list; - add a file to their theme's lists and place it in the design's
stylesheets/orjavascript/folder; - load the lists in a pagelayout with
ezcss_loadandezscript_load; - ask for a file from a single template with
ezcss_requireorezscript_require.
Trainer's notes
How to present it
Source: Stylesheets and scripts for your site.
The lists (5 minutes).
settings/design.ini:Setting Holds [StylesheetSettings] FrontendCSSFileList[]stylesheets for public designs [StylesheetSettings] BackendCSSFileList[]stylesheets for administration designs (extensions add theirs here) [StylesheetSettings] CSSFileList[]the older list for both; marked deprecated in design.iniin favor of the two above[JavaScriptSettings] FrontendJavaScriptList[],BackendJavaScriptList[],JavaScriptList[]the same for scripts A file name is looked up in
stylesheets/orjavascript/along the design chain.ezjsc::jqueryis ezjscore's own jQuery; a theme does not ship a copy.Loading them (4 minutes). The wizard's
page_head.tplandpagelayout.tplalready do it:{ezcss_load( array( ezini( 'StylesheetSettings', 'CSSFileList', 'design.ini' ), ezini( 'StylesheetSettings', 'FrontendCSSFileList', 'design.ini' ) ) )} ... {ezscript_load( array( 'ezjsc::jquery', ezini( 'JavaScriptSettings', 'JavaScriptList', 'design.ini' ), ezini( 'JavaScriptSettings', 'FrontendJavaScriptList', 'design.ini' ) ) )}Scripts are loaded at the end of the body, stylesheets in the head.
One file for one template (4 minutes). A view template that needs a file only on some pages calls
{ezcss_require( 'article.css' )}. The view runs before the pagelayout, so the pagelayout'sezcss_loadthen includes the file. The four functions are defined inextension/ezjscore/autoloads/ezjscpackertemplatefunctions.php.Why not a
<link>by hand (2 minutes). A hand-written link escapes the packer (one request per file, no modification time in the name) and cannot be extended or removed by settings.
Common questions
Should a theme still use CSSFileList[]? The wizard writes it and it works; new themes and reworked heads use
FrontendCSSFileList[] and FrontendJavaScriptList[]. In this lesson learners add to the frontend lists.
In which order are the files loaded? In the order of the lists as the pagelayout passes them, and inside a list in the order the settings files add entries (extensions in their loading order).
Can another extension add a file to my theme's pages? Yes, by adding to the same list in its own design.ini.
That is a reason to use the lists.
Pitfalls
- The file in the wrong folder.
FrontendCSSFileList[]=training.csslooks instylesheets/, not in the design root. A missing file leaves a warning in the debug output and is skipped. - Forgetting the INI cache. A new list entry needs
--clear-tag=ini; a new file also needs the packer and template caches (lesson 3.3). - A path with
stylesheets/in the list. Write the name relative tostylesheets/:training.css, orparts/menu.cssfor a subfolder.
Hands-on exercise
On your training installation. D stands for extension/training_theme/design/training_theme.
Open
extension/training_theme/settings/design.ini.append.phpand read the[StylesheetSettings]and[JavaScriptSettings]blocks the wizard wrote.Add, in
[StylesheetSettings]:FrontendCSSFileList[]=training.cssCreate
D/stylesheets/training.csswith a style for the skip link and the breadcrumb from lesson 2.2:.skip-link { position: absolute; inset-inline-start: -999em; } .skip-link:focus { position: static; } .training_theme-path { margin-block: 1rem; font-size: 0.9rem; }Create
D/stylesheets/article.csswith one visible rule, for example.training_theme-article h1 { font-size: 2.5rem; }.In
D/override/templates/full/article.tpl, add as the first line:{ezcss_require( 'article.css' )}.Clear the caches:
php bin/php/ezcache.php --clear-tag=ini,php bin/php/ezcache.php --clear-id=ezjscore-packer,php bin/php/ezcache.php --clear-tag=templateandphp bin/php/ezcache.php --clear-tag=content.Open a folder page of
<site>. In the page source, find the stylesheet<link>and open the file it names. Search it forskip-link.Open an article page and open its stylesheet file the same way. Search it for
training_theme-article.Press Tab once on a page: the skip link becomes visible.
Expected result
- Step 7: the page links one packed stylesheet whose content holds the rules of
training.css. - Step 8: on an article page the packed stylesheet also holds the rule of
article.css; on a folder page it does not. - Step 9: the skip link is hidden until it receives the focus.
- The trainer checks one learner's
design.ini.append.phpand the two packed files on the projector.
Quiz
- Which list does a public theme add its stylesheet to?
A.
BackendCSSFileList[]B.FrontendCSSFileList[]C.AdminComponentCSSFileList[]D.CustomHosts[] - In which folder of the design does
FrontendJavaScriptList[]=menu.jslook for the file? - Why does
ezcss_require( 'article.css' )in a view template reach the pagelayout'sezcss_load? - Why should a theme not ship its own copy of jQuery?
- Give two reasons against a hand-written
<link rel="stylesheet">in the pagelayout.
Answers
- B. The backend list is for administration designs (Stylesheets and scripts for your site).
- In
javascript/of the designs along the chain. - The view template runs before the pagelayout and its required files are collected;
ezcss_loadthen includes them. - ezjscore ships one (
ezjsc::jquery), so every extension uses the same version. - Any two: it is not packed (one request per file), it carries no modification time in its name, other extensions and settings cannot change it, and it does not follow the design chain.
Further reading
- Stylesheets and scripts for your site: the lists, the packer and the checklist.
- jQuery 4 and the removal of YUI: which jQuery ezjscore provides.
- Design settings a theme ships: which lists belong in the theme.
Related pages
- Module 3: Stylesheets and scripts through the packer
- Theme design: course overview
- Trainers: start here
- 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.