Hi. I’m an avid user of Sage and found myself using composers more and more.
I’m also using Bud bundler in an atomic way of loading page-specific styles, which I do from app/setup using wordpress conditionals.
use function Roots\bundle;
add_action('wp_enqueue_scripts', function () {
bundle('app')->enqueue();
if( is_page_template('sometemplate.blade.php') ) ){
bundle('assetspack')->enqueue();
}
if( is_front_page()){
bundle('homepack')->enqueue();
};
}, 100);
So far so good.
Now I would like to step that game further and be able to enqueue bundles in composers. My point is being able to contextualize css/js with templates variables/content. The granularity of $views is particularly appealing.
I know composers are for structuring datas for views only, but I feel that bundling scripts and css for those views could be considered a logical part of content, like they do in JS SPA frameworks.
So far,
public function __construct()
{
wp_enqueue_scripts(bundle('assetspack')->enqueue());
}
achieves what I desired.
However I don’t really know how to approach that,or even if there’s a more streamlined way to do it. What would you advise?
Thank you.