D
D
Dmitry Yakovlev2016-09-08 13:50:57
Yii
Dmitry Yakovlev, 2016-09-08 13:50:57

How to integrate a design template (theme) in Yii2?

Now I add themes in the following way:
- I copy the theme code to the themes/views/layouts/ folder,
- I write map in config

'components' => [
        'view' => [
            'theme' => [
                'pathMap' => [
                    '@app/views' => '@app/themes/otherLayouts',
                ],
            ],
        ],
    ],

- include css, js files in AssetBundle.
With this approach, there were problems with bootstrap styles and scripts.
1) Is this correct?
2) How do you apply other people's themes?
I know there are already ready-made themes in the form of modules, they are pulled up by composer, but I want to use others.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-09-08
@Pr0per

Good afternoon.
It would be better to make the structure like this:

themes/name_theme/layouts -> шаблон темы (main.php), с меню, шапкой и подвалом.
themes/name_theme/site -> виды темы
themes/name_theme/assets -> ресурсы (css, js и т.д.)

themes/name_theme/img -> images
Create a separate file, MyTheme (for example), which inherits from AssetBundle and include resource files in it. Specify the path to your resources
Place next to AssetBundle. Include this file in your theme template.
use app\assets\MyTheme;
MyTheme::register($this);

Add your theme in the config file:
'view' => [
           'theme' => [
              'basePath' => '@app/themes/name_theme',
              'baseUrl' => '@web/themes/name_theme',
              'pathMap' => [
                 '@app/views' => '@app/themes/name_theme'
              ]
           ]
        ],

There shouldn't be any problems connecting bootstrap or scripts. But if you do not use bootstrap in your theme, then it is better to remove this dependency altogether.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question