Hello,
I have the following simple View Composer in Sage 10:
<?php
namespace App\View\Composers;
use Roots\Acorn\View\Composer;
use function Roots\asset;
class Download extends Composer
{
/**
* List of views served by this composer.
*
* @var array
*/
protected static $views = [
'single-download'
];
/**
* Compose the view before rendering.
*
* @param \Illuminate\View\View $view
* @return void
*/
public function compose(\Illuminate\View\View $view)
{
$this->load_assets();
parent::compose($view);
}
/**
* Load assets
*
* @return void
*/
private function load_assets()
{
// load css
wp_register_style(
'pages-product',
asset('styles/pages/product.css')->uri(),
[],
MYTHEME_VERSION,
false
);
wp_enqueue_style( 'pages-product' );
}
}
which loads a CSS file for this particular partial (single-download.blade.php). The thing is that the CSS is loaded within the body and not within the head. This is to be expected since I do not use the action wp_enqueue_scripts.
When I try to use the above action it does not run at all, it appears the View Composer runs after that particular event. Is there any way to ensure the CSS file gets added at the head of the page? Is there a different approach in loading CSS/JS files per partial to ensure they are loaded at the start of the page load?