Skip to content

Commit

Permalink
[#72] Automatically render a template when visiting the parts kit roo…
Browse files Browse the repository at this point in the history
…t URL.
  • Loading branch information
joshuapease committed Jan 10, 2024
1 parent e120757 commit be05410
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';
}
);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/controllers/PartsKitController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
}
}
10 changes: 6 additions & 4 deletions src/templates/_layouts/parts-kit.html
Original file line number Diff line number Diff line change
@@ -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 %}
<meta name="robots" content="none">
{% endhtml %}

{% block content %}
{% block main %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ currentSite.name }} - Parts Kit</title>
{# Block all Robots #}
<meta name="robots" content="none">
</head>
<body>
Expand Down

0 comments on commit be05410

Please sign in to comment.