When View renders a view file, it will check the [[View::theme|active theme]]
to see if there is a themed version of the view file exists. If so, the themed version will be rendered instead.
A theme is a directory consisting of view files which are meant to replace their non-themed counterparts.
Theme uses [[pathMap]] to achieve the view file replacement:
1. It first looks for a key in [[pathMap]] that is a substring of the given view file path;
2. If such a key exists, the corresponding value will be used to replace the corresponding part
in the view file path;
3. It will then check if the updated view file exists or not. If so, that file will be used
to replace the original view file.
4. If Step 2 or 3 fails, the original view file will be used.
For example, if [[pathMap]] is ['@app/views' => '@app/themes/basic'],
then the themed version for a view file @app/views/site/index.php will be
@app/themes/basic/site/index.php.
It is possible to map a single path to multiple paths. For example,
~~~
'pathMap' => [
'@app/views' => [
'@app/themes/christmas',
'@app/themes/basic',
],
]
~~~
In this case, the themed version could be either @app/themes/christmas/site/index.php or
@app/themes/basic/site/index.php. The former has precedence over the latter if both files exist.
To use a theme, you should configure the [[View::theme|theme]] property of the "view" application
component like the following:
~~~
'view' => [
'theme' => [
'basePath' => '@app/themes/basic',
'baseUrl' => '@web/themes/basic',
],
],
~~~
The above configuration specifies a theme located under the "themes/basic" directory of the Web folder
that contains the entry script of the application. If your theme is designed to handle modules,
you may configure the [[pathMap]] property like described above.