0

I am building a custom module based upon the pluginfactory.io skeletons. I have registered my asset bundle and have verified my asset bundle is cached in the cpresources folder. But, the twig template does not have my css/js files loaded into the template. Am I missing something?
Here's the snippet where the assets are registered on the fly in the module.php:

        // Load our AssetBundle getIsSiteRequest() or getIsCpRequest()
    if (Craft::$app->getRequest()->getIsSiteRequest()) {
        Event::on(
            View::class,
            View::EVENT_BEFORE_RENDER_TEMPLATE,
            function (TemplateEvent $event) {
                try {
                    Craft::$app->getView()->registerAssetBundle(flexiformassets::class);
                } catch (InvalidConfigException $e) {
                    Craft::error(
                        'Error registering AssetBundle - '.$e->getMessage(),
                        __METHOD__
                    );
                }
            }
        );
    }

The call to render the template within my action controller works, I can see the form:

return Craft::$app->getView()->renderTemplate('_cceflexiform.twig', $formData);

The template itself renders the form (without styling). I even tried re-registering the asset bundle again inside the template, without success:

    {%  do view.registerAssetBundle("modules\\cceflexiformmodule\\assetbundles\\cceflexiformmodule\\flexiformassets") %}

I'm missing something basic, but I'm lost and have been spinning my wheels. Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.