ux icon indicating copy to clipboard operation
ux copied to clipboard

[TwigComponent] Allow passing functions / array variables to HTML syntax

Open weaverryan opened this issue 2 years ago • 9 comments

Hi!

This is something I keep wanting to do:

<twig:Button
    class="foo-bar">
    {{ stimulus_action('say', 'hello') }}
/>

I know why this doesn't work :). But from a user's perspective, I can't think of why it shouldn't. If we see a Twig {{ where we expect an attribute, then we should translate it effectively into a ...stimulus_action('say', 'hello') so its return value merges into the other props.

weaverryan avatar Nov 20 '23 01:11 weaverryan

Removed / off-topic

The closing > line 2 is a mistake.. or you suggest a new closing tag ?

Now for the stimulus_action method, it could be a ultra-easy... or a pure hell to implement.

The "context" there is the current template, not "in" the Button component (in a Twig-compiled-template point of vue)

Could you show an example with attributes, props before/after your suggestion ? I have something in mind but don't want to be "off-topic" :)

smnandre avatar Nov 20 '23 22:11 smnandre

Update your src/Twig/TwigPreLexer.php

and add this block line 209 (before the variadic check)

            if ($this->check('{{ stimulus_') || $this->check('{{stimulus_')) {
                $this->consume('{{');
                $attributes[] = '...' . trim($this->consumeUntil('}}'));
                $this->consume('}}');

                continue;
            }
            
            // rest of the file

            if ($this->check('{{...') || $this->check('{{ ...')) {
                $this->consume('{{...');

Is this the expected behaviour ?

smnandre avatar Nov 28 '23 00:11 smnandre

But now twig support the spread operator? I think we can do that at the stimulus_actionfunction level

WebMamba avatar Nov 28 '23 09:11 WebMamba

I'm not sure to get... how could we handle this inside the function ?

smnandre avatar Nov 28 '23 21:11 smnandre

I think I ran into the same problem.

I was trying to put symfony form stuff inside of a component like this:

<twig:ChipGroup {{ block('widget_container_attributes') }}>
    ....
</twig:ChipGroup>

It does not work which makes combining twig components and symfony forms quite difficult...

DemonTPx avatar Nov 29 '23 15:11 DemonTPx

You cannot "write content" inside the block tag (as you cannot inside any twig tag).. because it as a syntax.

This block should be on the div inside your template

smnandre avatar Nov 29 '23 18:11 smnandre

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?

carsonbot avatar May 30 '24 12:05 carsonbot

Just a quick reminder to make a comment on this. If I don't hear anything I'll close this.

carsonbot avatar Jun 13 '24 12:06 carsonbot

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

carsonbot avatar Jun 27 '24 12:06 carsonbot

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?

carsonbot avatar Dec 28 '24 12:12 carsonbot

Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3

carsonbot avatar Jan 11 '25 12:01 carsonbot