theming.md 1.75 KB
Newer Older
1 2 3
Theming
=======

4 5 6 7 8 9
A theme is a directory of view and layout files. Each file of the theme overrides corresponding file of an application
when rendered. A single application may use multiple themes and each may provide totally different experience. At any
time only one theme can be active.

> Note: Themes usually do not meant to be redistributed since views are too application specific. If you want to
  redistribute customized look and feel consider CSS and JavaScript files in form of [asset bundles](assets.md) instead.
10 11 12 13 14 15 16 17 18

Configuring current theme
-------------------------

Theme configuration is specified via `view` component of the application. So in order to set it up the following should
be in your application config file:

```php
'components' => [
19 20
    'view' => [
        'theme' => [
21
            'pathMap' => ['@app/views' => '@app/themes/basic'],
22 23 24
            'baseUrl' => '@web/themes/basic',
        ],
    ],
25
],
26 27 28
```

In the above `pathMap` defines where to look for view files while `baseUrl` defines base URL for resources referenced
29 30
from these files. In our case `pathMap` is `['@app/views' => '@app/themes/basic']` so the themed version
for a view file `@app/views/site/index.php` will be `@app/themes/basic/site/index.php`.
31 32 33 34 35 36 37 38

Using multiple paths
--------------------

It is possible to map a single path to multiple paths. For example,

```php
'pathMap' => [
39 40 41
    '@app/views' => [
        '@app/themes/christmas',
        '@app/themes/basic',
42
    ],
43 44 45
]
```

46 47
In this case, the view will be searched in `@app/themes/christmas/site/index.php` then if it's not found it will check
`@app/themes/basic/site/index.php`. If there's no view there as well application view will be used.
48 49

This ability is especially useful if you want to temporary or conditionally override some views.