diff --git a/src/Module.php b/src/Module.php index bf2ff66..d4bbe60 100644 --- a/src/Module.php +++ b/src/Module.php @@ -3,6 +3,8 @@ namespace viget\base; use Craft; +use craft\events\RegisterUrlRulesEvent; +use craft\web\UrlManager; use yii\base\BootstrapInterface; use yii\base\Event; use craft\events\RegisterCpNavItemsEvent; @@ -175,6 +177,17 @@ function (RegisterTemplateRootsEvent $e) { } ); } + + // Override rendering of the root /parts-kit URL, so we can render a custom template that + // injects the HTML / JS for our parts kit UI. + Event::on( + UrlManager::class, + UrlManager::EVENT_REGISTER_SITE_URL_RULES, + function (RegisterUrlRulesEvent $event) { + $partsKitDir = self::$config['partsKit']['directory']; + $event->rules[$partsKitDir] = 'parts-kit/root'; + } + ); } /** diff --git a/src/controllers/PartsKitController.php b/src/controllers/PartsKitController.php index 677df9c..9ddb1a4 100644 --- a/src/controllers/PartsKitController.php +++ b/src/controllers/PartsKitController.php @@ -17,4 +17,11 @@ public function actionConfig(): Response 'nav' => Module::getInstance()->partsKit->getNav(), ]); } + + public function actionRoot(): Response + { + return $this->renderTemplate( + 'viget-base/parts-kit-root', + ); + } } diff --git a/src/templates/_layouts/parts-kit.html b/src/templates/_layouts/parts-kit.html index d356bbf..ffeed24 100644 --- a/src/templates/_layouts/parts-kit.html +++ b/src/templates/_layouts/parts-kit.html @@ -1,7 +1,9 @@ -{% extends craft.viget.partsKit.isRootRequest() - ? 'viget-base/_layouts/parts-kit-root' - : craft.viget.partsKit.getConfig('layout') -%} +{% extends craft.viget.partsKit.getConfig('layout') %} + +{# Block all Robots #} +{% html at head %} + +{% endhtml %} {% block content %} {% block main %} diff --git a/src/templates/_layouts/parts-kit-root.html b/src/templates/parts-kit-root.html similarity index 94% rename from src/templates/_layouts/parts-kit-root.html rename to src/templates/parts-kit-root.html index 7fc3e11..2cca235 100644 --- a/src/templates/_layouts/parts-kit-root.html +++ b/src/templates/parts-kit-root.html @@ -4,6 +4,7 @@