N
N
nepster-web2014-12-07 20:09:14
Yii
nepster-web, 2014-12-07 20:09:14

Yii2 twig, how to register my assets?

I climbed on this doc https://github.com/yiisoft/yii2/blob/master/docs/g...
But everything is beautifully described there for smart, for twig it is rather poor.
Globally, you can register something like this:

'globals' => [
                        'siteAssets' => 'frontend\themes\basic\assets\AppAsset',
                    ],
    {{ void( siteAssets.register(this) ) }}

But what if you need to register an asset just for one page. I tried to do it like this:
{{ use('frontend/themes/basic/assets/AppAsset') }}
{{ void( AppAsset.register(this) ) }}

Nice try, but nothing worked. Can you please tell me how to register assets not globally?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2014-12-07
Protko @Fesor

{{ use('frontend/themes/basic/assets/AppAsset') }}
{{ void( AppAsset.register(this) ) }}

What is this trash anyway? Couldn't it have been made somehow more convenient... more concise... Add functions/nodes for registering the use of assets... It's easy to do in Twig, I can't think of anything that can't be done in Twig, taking into account the fact that you have access to the AST and you can influence the generated PHP code. And here some casters with void ...
My advice to you is to make a normal Twig bridge without these casters with statics and calls to register(this) methods in templates. At least it will be good for the community.

P
phpnt, 2015-03-06
@phpnt

Adding CSS, JS, JQuery and more to Yii... - detailed video in Russian

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question