Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TwigComponent] Allow Index view for Anonymous Components #1192

Closed
wants to merge 0 commits into from
Closed

[TwigComponent] Allow Index view for Anonymous Components #1192

wants to merge 0 commits into from

Conversation

seb-jean
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
Tickets Fix #1060
License MIT

I created this PR using the example on laravel/framework#38847.

Currently we can get the code below but the Accordion and Item template will not be in the same directory.

<twig:Accordion>
    <twig:Accordion:Item>...</twig:Accordion:Item>
    <twig:Accordion:Item>...</twig:Accordion:Item>
</twig:Accordion>

But we could do it by doing <twig:Accordion:Accordion> but that's weird.

With this functionality, it allows you to structure the components well. Here we will then have:
components/Accordion/Index.html.twig
components/Accordion/Item.html.twig

@@ -50,6 +50,22 @@ public function findAnonymousComponentTemplate(string $name): ?string
return $componentPath;
}

if ($loader->exists('components/'.$componentPath.'/Index.html.twig')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed here i think (legacy behaviour)

@smnandre
Copy link
Member

smnandre commented Oct 16, 2023

On one hand, i clearly see the DX benefit for front-end development.

On the other hand, this break some things / raise some questions:

  • we cannot "just add a class Accordion.php" to add PHP computation.. because the associated template would be "Accordion.html.twig" and that was a big need for the anonymous
  • a component can be called by two names now (twig:Accordion and twig:Accordion:Index)
  • the debug / suggest tools will have more checks to do

None of those are blocking points, but that deserve a bit of thinking i guess.

Update: that also would create two separate behaviour (depending of class-based or anonymous component)

@seb-jean
Copy link
Contributor Author

Thank you for your answer

@seb-jean
Copy link
Contributor Author

seb-jean commented Nov 2, 2023

@smnandre Do you know how to move forward with this PR?

@WebMamba
Copy link
Contributor

WebMamba commented Nov 2, 2023

I am sorry but I am not sure about this PR. Because of the reasons @smnandre mention and I don't like the idea of adding new conventions. We want people to feel free to write their code how they wanted without looking at conventions. This PR: #1209 could be a solution for your issue. We just have some fix to do before it get merged 😁

@seb-jean seb-jean closed this Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TwigComponent] Anonymous Index Components
3 participants