Package requireAsset

Permalink
Until now I always put requireAsset in the on_start of a Package controller. But I noticed that e.g. for tool files all packages are loaded and the on_start method is executed.

This results in JS / CSS included if you have requireAsset calls in your on_start method. This is very inconvenient. E.g. in composer the field "page_slug" does a tool call. When using requireAsset in a package, the <script> and <link> tags appear in the page slug field...

How do you guys require assets in Packages? Any suggestions?

A3020
 
Remo replied on at Permalink Reply
Remo
I always put them in my controller method, e.g. view, add to ensure I only include what I need. Requires more code though..
martbase replied on at Permalink Reply
Hi Remo,

I have a similar issue but with custom templates for core blocks in a package.

Overriding the recommended registerViewAssets() method in the block controller (inside blocks in custom package) does not seem to work so I have resorted to using requireAsset in the package on_start method.

Does your solution work even with block caching on?

Here is my forum question linkhttp://www.concrete5.org/community/forums/5-7-discussion/extendover...

Thanks
A3020 replied on at Permalink Reply
A3020
On IRC they suggested me to put the code in the single page controllers. That works. Well hopefully other developers won't put the requireAsset in the on_start of the package controller cause the WILL cause problems.