Add support for docs property for BlockNode and TypesNode#4770
Add support for docs property for BlockNode and TypesNode#4770Kocal wants to merge 1 commit intotwigphp:3.xfrom
docs property for BlockNode and TypesNode#4770Conversation
aeb35b7 to
1181325
Compare
1181325 to
ce52af9
Compare
| $compiler | ||
| ->addDebugInfo($this) | ||
| ->write("/**\n") | ||
| ->write($this->hasAttribute('docs') ? ' * '.str_replace("\n", "\n * ", $this->getAttribute('docs'))."\n" : '') |
stof
left a comment
There was a problem hiding this comment.
With the introduction of the assignment operator, I think this proposal is ambiguous for blocks as {% block content docs="Hello world!" %} is a valid code already, using docs="Hello world!" as the expression (even though assigning a docs variable in that scope is quite useless, as the block is the scope boundary)
| $compiler | ||
| ->addDebugInfo($this) | ||
| ->write("/**\n") | ||
| ->write($this->hasAttribute('docs') ? ' * '.str_replace("\n", "\n * ", $this->getAttribute('docs'))."\n" : '') |
There was a problem hiding this comment.
This need to handle cases where the content of the attribute contains */, to make sure it does not ends the PHP comment.
|
|
||
| // Check for optional docs="..." attribute | ||
| $docs = null; | ||
| if ($stream->test(Token::NAME_TYPE, 'docs')) { |
There was a problem hiding this comment.
this is breaking existing code if the block is using an expression starting with a docs variable or function.
I think it needs to be parsed after the expression, not before it, for the case using the expression-based content.
|
I think |
|
@Kocal the |


Close #4768
(Code generated almost entirely using Claude Opus 4.5.)
The following code is now valid (essential parts of our UX Toolkit Shadcn Button component):
{%- types { variant: "'default'|'secondary'|'destructive'|'outline'|'ghost'|'link'" docs="Visual style variant.", size: "'default'|'xs'|'sm'|'lg'|'icon'|'icon-xs'|'icon-sm'|'icon-lg'" docs="The button size.", button: '"button"' docs="The HTML tag to render.", } -%} {%- block content docs="The button label and/or icon" %}{% endblock -%}