How can I register an assetbundle in a frontend template? This is my bundle
namespace secondred\formbuilder\assetbundles\Formbuilder;
use Craft;
use craft\web\AssetBundle;
use craft\web\assets\cp\CpAsset;
class FormbuilderAsset extends AssetBundle
{
// Public Methods
// =========================================================================
/**
* Initializes the bundle.
*/
public function init()
{
// define the path that your publishable resources live
$this->sourcePath = "@secondred/formbuilder/assetbundles/formbuilder/dist";
// define the dependencies
$this->depends = [
CpAsset::class,
];
// define the relative path to CSS/JS files that should be registered with the page
// when this asset bundle is registered
$this->js = [
'js/Formbuilder.js',
];
$this->css = [
'css/Formbuilder.css',
];
parent::init();
}
}
And I can register it with in my controller without any problems
$this->view->registerAssetBundle(FormbuilderAsset::class);
But when I do
{% do view.registerAssetBundle("secondred\\formbuilder\\assetbundles\\formbuilder\\FormbuilderAsset") %}
nothing happens.. no request, no error, nothing in network tab and no html is added to the page
Update
I found the solution. If you are in a frontend ressource you need to call the {{ endBody() }}
method in order to get the bundles
{% do view.registerAssetBundle("secondred\\formbuilder\\assetbundles\\Formbuilder\\FormbuilderAsset") %}
{{ endBody() }}
in my frontend template. Maybe it is worth mentioning in the documents? github.com/craftcms/docs/blob/master/en/asset-bundles.md