diff --git a/src/services/PartsKit.php b/src/services/PartsKit.php index cca1206..2d73bf2 100644 --- a/src/services/PartsKit.php +++ b/src/services/PartsKit.php @@ -122,6 +122,20 @@ public static function getNav(): array return array_values($result); } + /** + * The JS file for the parts kit UI library. This needs to be added on both the + * parts kit root page and on each "part" page. + * + * unpkg.com respects server. This URL will need to be adjusted when major versions + * are released. + * + * @return string + */ + public static function getUiScriptUrl(): string + { + return 'https://unpkg.com/@viget/parts-kit@^0/lib/parts-kit.js'; + } + /** * Remove extension from file name * diff --git a/src/templates/_layouts/parts-kit.html b/src/templates/_layouts/parts-kit.html index ffeed24..12b1248 100644 --- a/src/templates/_layouts/parts-kit.html +++ b/src/templates/_layouts/parts-kit.html @@ -5,6 +5,10 @@ {% endhtml %} +{% js craft.viget.partsKit.getUiScriptUrl() with { + type: 'module', +} %} + {% block content %} {% block main %} {% endblock %} diff --git a/src/templates/parts-kit-root.html b/src/templates/parts-kit-root.html index 2cca235..bd8d0af 100644 --- a/src/templates/parts-kit-root.html +++ b/src/templates/parts-kit-root.html @@ -8,10 +8,7 @@ - +