diff --git a/src/helpers/ComponentViewerHelper.php b/src/helpers/ComponentViewerHelper.php index 02de173..b9bc0c6 100644 --- a/src/helpers/ComponentViewerHelper.php +++ b/src/helpers/ComponentViewerHelper.php @@ -130,8 +130,15 @@ public static function getComponent($componentId = '', $variant = null): array $componentConfigPath = $componentMap[$componentId]; $twigString = file_get_contents($componentConfigPath); $componentConfig = Json::decode(file_get_contents(self::getComponentConfigPath($componentConfigPath))); + $context = self::getComponentContext($componentId, $variant); + + // Override the default context with the variant context + if ($context) { + $componentConfig['context'] = $context; + } + try { - $rendered = Craft::$app->view->renderString($twigString, self::getComponentContext($componentId, $variant)); + $rendered = Craft::$app->view->renderString($twigString, $context); } catch (\Exception $e) { $rendered = $e->getMessage(); } @@ -139,7 +146,14 @@ public static function getComponent($componentId = '', $variant = null): array try { $readme = file_get_contents(self::getComponentReadmePath($componentId, $componentConfigPath)); } catch (\Exception) { - $readme = 'Tags: {{ tags|join(",") }}

{{ title }}: {{ handle }}

{% include "@{{ handle }}" with {{ jsonPrettyPrint(context) }} %}
'; + $readme = 'Tags: {{ tags|join(",") }}

{{ title }}: {{ handle }}

{% include \'@{{ handle }}\'';
+            
+            // Only show `with { … }` in the include example if context exists
+            if ($context) {
+                $readme = $readme . ' with {{ context|json_encode(constant(\'JSON_PRETTY_PRINT\')) }}';
+            }
+
+            $readme = $readme . ' %}
'; } try { $parser = new Markdown(); @@ -151,7 +165,7 @@ public static function getComponent($componentId = '', $variant = null): array return [ 'config' => $componentConfig, - 'context' => self::getComponentContext($componentId, $variant), + 'context' => $context, 'readme' => $readme, 'twig' => $twigString, 'rendered' => $rendered, diff --git a/src/templates/_components/atoms/btn/btn.twig b/src/templates/_components/atoms/btn/btn.twig index 291979a..5dec9de 100644 --- a/src/templates/_components/atoms/btn/btn.twig +++ b/src/templates/_components/atoms/btn/btn.twig @@ -12,10 +12,10 @@ {% endif %} {% if href is defined and href is not null %} +? ' disabled' }} {{ attrs is defined ? attr(attrs) }}> {% else %}