Recreating React style components in Twig
I have recently been learning React and really like the how I can build a page using reusable React components. I have also been using TailwindCSS for sometime and the combination of the 2, to me, really makes sense.
I was looking at trying to recreate a similar approach in Twig. I have come up with the following as a first attempt. I was just wondering if anyone else has been down this rabbit hole and how you solved it?
{% extends 'application.html.twig' %}
{% block main %}
{% embed '@VendorBundle/PageContainer.html.twig' %}
{% block children %}
{% embed '@VendorBundle/PageHeader.html.twig' %}
{% block noscript %}Users{% endblock %}
{% block children %}
{% embed '@VendorBundle/Button/Primary.html.twig' %}
{% block href %}{{ path('name_of_path') }}{% endblock %}
{% block children %}
{{ ux_icon('bi:plus', {class: 'w-3 h-3'}) }}
Add New
{% endblock %}
{% endembed %}
{% endblock %}
{% endembed %}
{% embed '@VendorBundle/Table/TableContainer.html.twig' %}
{% block children %}
{% embed '@VendorBundle/Table/Table.html.twig' %}
{% block children %}
{% embed '@VendorBundle/Table/TableHead.html.twig' %}
{% block children %}
{% embed '@VendorBundle/Table/TableHeadRow.html.twig' %}
{% block children %}
{% embed '@VendorBundle/Table/TableHeader.html.twig' %}
{% block children %}Name{% endblock %}
{% endembed %}
{% embed '@VendorBundle/Table/TableHeader.html.twig' %}
{% block children %}Email{% endblock %}
{% endembed %}
{% embed '@VendorBundle/Table/TableHeader.html.twig' %}
{% block children %}<span class="sr-only">Actions</span>{% endblock %}
{% endembed %}
{% endblock %}
{% endembed %}
{% endblock %}
{% endembed %}
{% embed '@VendorBundle/Table/TableBody.html.twig' %}
{% block children %}
{% for user in users %}
{% embed '@VendorBundle/Table/TableBodyRow.html.twig' %}
{% block children %}
{% embed '@VendorBundle/Table/TableData.html.twig' %}
{% block children %}
{{ user.firstName }} {{ user.lastName }}
{% endblock %}
{% endembed %}
{% embed '@VendorBundle/Table/TableData.html.twig' %}
{% block children %}
<a href="mailto:{{ user.emailAddress }}" class="underline hover:no-underline">{{ user.emailAddress }}</a>
{% endblock %}
I have recently been learning React and really like the how I can build a page using reusable React components. I have also been using TailwindCSS for sometime and the combination of the 2, to me, really makes sense.
I was looking at trying to recreate a similar approach in Twig. I have come up with the following as a first attempt. I was just wondering if anyone else has been down this rabbit hole and how you solved it?
{% extends 'application.html.twig' %}
{% block main %}
{% embed '@VendorBundle/PageContainer.html.twig' %}
{% block children %}
{% embed '@VendorBundle/PageHeader.html.twig' %}
{% block noscript %}Users{% endblock %}
{% block children %}
{% embed '@VendorBundle/Button/Primary.html.twig' %}
{% block href %}{{ path('name_of_path') }}{% endblock %}
{% block children %}
{{ ux_icon('bi:plus', {class: 'w-3 h-3'}) }}
Add New
{% endblock %}
{% endembed %}
{% endblock %}
{% endembed %}
{% embed '@VendorBundle/Table/TableContainer.html.twig' %}
{% block children %}
{% embed '@VendorBundle/Table/Table.html.twig' %}
{% block children %}
{% embed '@VendorBundle/Table/TableHead.html.twig' %}
{% block children %}
{% embed '@VendorBundle/Table/TableHeadRow.html.twig' %}
{% block children %}
{% embed '@VendorBundle/Table/TableHeader.html.twig' %}
{% block children %}Name{% endblock %}
{% endembed %}
{% embed '@VendorBundle/Table/TableHeader.html.twig' %}
{% block children %}Email{% endblock %}
{% endembed %}
{% embed '@VendorBundle/Table/TableHeader.html.twig' %}
{% block children %}<span class="sr-only">Actions</span>{% endblock %}
{% endembed %}
{% endblock %}
{% endembed %}
{% endblock %}
{% endembed %}
{% embed '@VendorBundle/Table/TableBody.html.twig' %}
{% block children %}
{% for user in users %}
{% embed '@VendorBundle/Table/TableBodyRow.html.twig' %}
{% block children %}
{% embed '@VendorBundle/Table/TableData.html.twig' %}
{% block children %}
{{ user.firstName }} {{ user.lastName }}
{% endblock %}
{% endembed %}
{% embed '@VendorBundle/Table/TableData.html.twig' %}
{% block children %}
<a href="mailto:{{ user.emailAddress }}" class="underline hover:no-underline">{{ user.emailAddress }}</a>
{% endblock %}
{% endembed %}
{% embed '@VendorBundle/Table/TableData.html.twig' with {'classes': 'flex items-center justify-end'} %}
{% block children %}
<button id="actions-{{ loop.index }}-dropdown-button" data-dropdown-toggle="actions-{{ loop.index }}-dropdown" class="inline-flex items-center p-0.5 text-sm font-medium text-center text-gray-500 hover:text-gray-800 rounded-lg focus:outline-none dark:text-gray-400 dark:hover:text-gray-100" type="button">
{{ ux_icon('bi:three-dots', {class: 'w-5 h-5'}) }}
</button>
<div id="actions-{{ loop.index }}-dropdown" class="hidden z-10 w-44 bg-white rounded divide-y divide-gray-100 shadow dark:bg-gray-700 dark:divide-gray-600">
<ul class="py-1 text-sm text-gray-700 dark:text-gray-200" aria-labelledby="actions-{{ loop.index }}-dropdown-button">
<li>
<a href="{{ path('name_of_path', { id: user.accountId }) }}" class="block py-2 px-4 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Edit</a>
</li>
</ul>
<div class="py-1">
<a href="{{ path('name_of_path', { id: user.accountId }) }}" class="block py-2 px-4 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white">Delete</a>
</div>
</div>
{% endblock %}
{% endembed %}
{% endblock %}
{% endembed %}
{% endfor %}
{% endblock %}
{% endembed %}
{% endblock %}
{% endembed %}
{% embed '@VendorBundle/Table/TablePagination.html.twig' with {'pagination': users} only %}{% endembed %}
{% endblock %}
{% endembed %}
{% endblock %}
{% endembed %}
{% endblock %}
// VendorBundle/PageHeader.html.twig
<div class="flex items-center justify-between space-x-3 w-full md:w-auto pb-4">
<h1 class="text-4xl font-bold text-gray-900 dark:text-white">{% block noscript %}{% endblock %}</h1>
{% block children %}{% endblock %}
</div>
https://redd.it/1j5l6zm
@r_php
{% embed '@VendorBundle/Table/TableData.html.twig' with {'classes': 'flex items-center justify-end'} %}
{% block children %}
<button id="actions-{{ loop.index }}-dropdown-button" data-dropdown-toggle="actions-{{ loop.index }}-dropdown" class="inline-flex items-center p-0.5 text-sm font-medium text-center text-gray-500 hover:text-gray-800 rounded-lg focus:outline-none dark:text-gray-400 dark:hover:text-gray-100" type="button">
{{ ux_icon('bi:three-dots', {class: 'w-5 h-5'}) }}
</button>
<div id="actions-{{ loop.index }}-dropdown" class="hidden z-10 w-44 bg-white rounded divide-y divide-gray-100 shadow dark:bg-gray-700 dark:divide-gray-600">
<ul class="py-1 text-sm text-gray-700 dark:text-gray-200" aria-labelledby="actions-{{ loop.index }}-dropdown-button">
<li>
<a href="{{ path('name_of_path', { id: user.accountId }) }}" class="block py-2 px-4 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white">Edit</a>
</li>
</ul>
<div class="py-1">
<a href="{{ path('name_of_path', { id: user.accountId }) }}" class="block py-2 px-4 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white">Delete</a>
</div>
</div>
{% endblock %}
{% endembed %}
{% endblock %}
{% endembed %}
{% endfor %}
{% endblock %}
{% endembed %}
{% endblock %}
{% endembed %}
{% embed '@VendorBundle/Table/TablePagination.html.twig' with {'pagination': users} only %}{% endembed %}
{% endblock %}
{% endembed %}
{% endblock %}
{% endembed %}
{% endblock %}
// VendorBundle/PageHeader.html.twig
<div class="flex items-center justify-between space-x-3 w-full md:w-auto pb-4">
<h1 class="text-4xl font-bold text-gray-900 dark:text-white">{% block noscript %}{% endblock %}</h1>
{% block children %}{% endblock %}
</div>
https://redd.it/1j5l6zm
@r_php
Reddit
From the symfony community on Reddit
Explore this post and more from the symfony community
Laravel Cloud blocking iframes
I was evaluating Laravel Cloud as an alternative to Heroku recently and found that it's not suitable for our BigCommerce & Shopify apps as they add an "X-Frame-Options: Deny" header.
This essentially blocks our apps from loading as both platforms use iframes. I've spoken to support and it doesn't sound like it's an option that Laravel are going to provide in the short term.
Has anyone come up with a workaround? Perhaps Cloudflare could remove the header?
https://redd.it/1j5pg3x
@r_php
I was evaluating Laravel Cloud as an alternative to Heroku recently and found that it's not suitable for our BigCommerce & Shopify apps as they add an "X-Frame-Options: Deny" header.
This essentially blocks our apps from loading as both platforms use iframes. I've spoken to support and it doesn't sound like it's an option that Laravel are going to provide in the short term.
Has anyone come up with a workaround? Perhaps Cloudflare could remove the header?
https://redd.it/1j5pg3x
@r_php
Reddit
From the laravel community on Reddit
Explore this post and more from the laravel community
The right way to achieve confirmation before committing to database?
Hi All,
Basically I would like to have a confirmation from user once he has enter data and press submit button. The use case is as below:
1. User enters all the necessary data.
2. User press submit button.
3. User is presented with data he inputted and asked to confirm if he is sure about the data and if he want to confirm submission.
4.User confirms and then data is committed to db.
I am thinking about having two methods inside controller. Controller method 1 prepare and render form in step 1 and 2. Then it reroute the user to controller method 2.
CController method 2 will then process the step 3 and 4.
Is this right way to do?
https://redd.it/1j5paac
@r_php
Hi All,
Basically I would like to have a confirmation from user once he has enter data and press submit button. The use case is as below:
1. User enters all the necessary data.
2. User press submit button.
3. User is presented with data he inputted and asked to confirm if he is sure about the data and if he want to confirm submission.
4.User confirms and then data is committed to db.
I am thinking about having two methods inside controller. Controller method 1 prepare and render form in step 1 and 2. Then it reroute the user to controller method 2.
CController method 2 will then process the step 3 and 4.
Is this right way to do?
https://redd.it/1j5paac
@r_php
Reddit
From the symfony community on Reddit
Explore this post and more from the symfony community
Assert that response has element works locally, fails on GitHub Actions
All my tests work locally, but most fail on GitHub Actions:
These are all the functional tests that actually request a page.
Example:
Could
https://redd.it/1j5ugri
@r_php
All my tests work locally, but most fail on GitHub Actions:
F..FEEEEFEEEEEE...FEEEEEEEEEFFFE.EE....FF....FFEEE..EEEF.FFFFFF 63 / 125 ( 50%)
FFF.FFFFFFFFF.FF.............................................. 125 / 125 (100%)
These are all the functional tests that actually request a page.
Example:
App\Tests\SignUpControllerTest::test_page_is_only_accessible_to_guests
Failed asserting that the Response status code is 200.
HTTP/1.1 500 Internal Server Error
public function test_page_is_only_accessible_to_guests(): void
{
exec('php bin/console doctrine:fixtures:load ' . UserFixtures::class . ' --env=test --no-interaction');
if (!self::$booted)
{
self::bootKernel();
}
/** @var KernelBrowser $browser */
$browser = self::getContainer()->get('test.client');
$browser->setServerParameters([
'HTTP_HOST' => 'localhost:8000',
'HTTPS' => false,
]);
/** @var KernelBrowser $browser */
$browser = self::getClient($browser);
$browser->request(Request::METHOD_GET, $route);
$this->assertResponseStatusCodeSame(Response::HTTP_OK);
}
Could
'HTTP_HOST' => 'localhost:8000' be the culprit? How to make this compatible with GitHub CI/CD?https://redd.it/1j5ugri
@r_php
Reddit
From the symfony community on Reddit
Explore this post and more from the symfony community
Feedback for my framework - Forge modular explicit framework
Hello people i want share this project that i've been working on it, its an explicit php framework without magic this is still in very heavy development but i would love to hear your feedback, the name is Forge, because i see it more like a toolkit that you can choose what you need, any type of feedback is welcome, Thanks.
\- Here is the Repo: https://github.com/forge-engine/forge
\- Documentation: https://forge-engine.github.io/
https://redd.it/1j61ec5
@r_php
Hello people i want share this project that i've been working on it, its an explicit php framework without magic this is still in very heavy development but i would love to hear your feedback, the name is Forge, because i see it more like a toolkit that you can choose what you need, any type of feedback is welcome, Thanks.
\- Here is the Repo: https://github.com/forge-engine/forge
\- Documentation: https://forge-engine.github.io/
https://redd.it/1j61ec5
@r_php
GitHub
GitHub - forge-engine/forge: Forge Framework Repo
Forge Framework Repo. Contribute to forge-engine/forge development by creating an account on GitHub.
Executable path
I want to start learning php but when I make a .php, it makes me edit the php.validate.executablepath, how do I edit this?
https://redd.it/1j60l18
@r_php
I want to start learning php but when I make a .php, it makes me edit the php.validate.executablepath, how do I edit this?
https://redd.it/1j60l18
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
Is Laravel Broadcasting suitable for real-time online game?
I struggle to understand how multiplayer online games work with WebSockets. I've always thought that they keep one connection open for both sides of the communication - sending and receiving, so the latency is as minimal as possible.
However, Laravel seems to suggest sending messages via WebSockets through axios or fetch API, which is where I'm confused. Isn't creating new HTTP requests considered slow? There is a lot going on to dispatch a request, bootstrap the app etc. Doesn't it kill all the purpose of WebSocket connection, which is supposed to be almost real-time?
Is PHP a suboptimal choice for real-time multiplayer games in general? Do some other languages or technologies keep the app open in memory, so HTTP requests are not necessary? It's really confusing to me, because I haven't seen any tutorials using Broadcasting without axios or fetch.
How do I implement a game that, for example, stores my action in a database and sends it immediately to other players?
https://redd.it/1j64tak
@r_php
I struggle to understand how multiplayer online games work with WebSockets. I've always thought that they keep one connection open for both sides of the communication - sending and receiving, so the latency is as minimal as possible.
However, Laravel seems to suggest sending messages via WebSockets through axios or fetch API, which is where I'm confused. Isn't creating new HTTP requests considered slow? There is a lot going on to dispatch a request, bootstrap the app etc. Doesn't it kill all the purpose of WebSocket connection, which is supposed to be almost real-time?
Is PHP a suboptimal choice for real-time multiplayer games in general? Do some other languages or technologies keep the app open in memory, so HTTP requests are not necessary? It's really confusing to me, because I haven't seen any tutorials using Broadcasting without axios or fetch.
How do I implement a game that, for example, stores my action in a database and sends it immediately to other players?
https://redd.it/1j64tak
@r_php
Reddit
From the laravel community on Reddit
Explore this post and more from the laravel community
DAE get frustrated when searching for a Composer package for "foo" and only find "laravel-foo"?
I get that many people use Laravel, but like myself, many don't. I'd much rather use independent packages that are not wired in to illuminate or whatever. Why not make an independent package for the functionality, and then add a bridge/wrapper for Laravel? That way you can support many frameworks if you so choose.
https://redd.it/1j67jov
@r_php
I get that many people use Laravel, but like myself, many don't. I'd much rather use independent packages that are not wired in to illuminate or whatever. Why not make an independent package for the functionality, and then add a bridge/wrapper for Laravel? That way you can support many frameworks if you so choose.
https://redd.it/1j67jov
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
Whats your approach for realtime applications on shared hosts
When it comes to realtime web applications, its always things like ReactPHP, or nodejs based websocket, or similar tools that are not really an option on shared hosts.
The next obvious thing would be SSE, but because of the usual low php process limit, this isnt an option as well if youre not the only person using the application...
So I'm curious what do others use? Is a 3rd party tool like pusher the only option?
https://redd.it/1j6eqae
@r_php
When it comes to realtime web applications, its always things like ReactPHP, or nodejs based websocket, or similar tools that are not really an option on shared hosts.
The next obvious thing would be SSE, but because of the usual low php process limit, this isnt an option as well if youre not the only person using the application...
So I'm curious what do others use? Is a 3rd party tool like pusher the only option?
https://redd.it/1j6eqae
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
How to Strangle your Project with Strangle Anti-Pattern
https://getrector.com/blog/how-to-strangle-your-project-with-strangle-anti-pattern
https://redd.it/1j6icv2
@r_php
https://getrector.com/blog/how-to-strangle-your-project-with-strangle-anti-pattern
https://redd.it/1j6icv2
@r_php
Getrector
How to Strangle your Project with Strangle Anti-Pattern
Nearly half of the projects we help upgrade have tried the upgrade before on their own.
They've introduced the infamous "strangle pattern". It's a way to upgrade a project separating one part of the codebase from the rest at a time.
Those companies reach…
They've introduced the infamous "strangle pattern". It's a way to upgrade a project separating one part of the codebase from the rest at a time.
Those companies reach…
LarAgent v0.2.0 Released
Hello, Laravel devs! Just released a new version with updates:
* Support for Laravel 12
* Dynamic model setting
* New command for batch cleaning of chat histories `php artisan agent:chat:clear AgentName`
Check the release notes here:
[https://github.com/MaestroError/LarAgent/releases/tag/0.2.0](https://github.com/MaestroError/LarAgent/releases/tag/0.2.0)
https://redd.it/1j6jbmc
@r_php
Hello, Laravel devs! Just released a new version with updates:
* Support for Laravel 12
* Dynamic model setting
* New command for batch cleaning of chat histories `php artisan agent:chat:clear AgentName`
Check the release notes here:
[https://github.com/MaestroError/LarAgent/releases/tag/0.2.0](https://github.com/MaestroError/LarAgent/releases/tag/0.2.0)
https://redd.it/1j6jbmc
@r_php
GitHub
Release 0.2.0 · MaestroError/LarAgent
What's new in LarAgent?
Support for Laravel 12
Dynamic model setting via chainable withModel and overridable model methods
New command for batch cleaning of chat histories php artisan agent:ch...
Support for Laravel 12
Dynamic model setting via chainable withModel and overridable model methods
New command for batch cleaning of chat histories php artisan agent:ch...
🚀 Laravel 12 – The Future of Laravel? Controversy, Starter Kits & Laravel Cloud!
https://youtu.be/yDNqi2EZ2Uo
https://redd.it/1j6mxvd
@r_php
https://youtu.be/yDNqi2EZ2Uo
https://redd.it/1j6mxvd
@r_php
Laravext Starter Kits for Laravel
I'm happy to announce the new Laravext Starter Kits, based on Laravel 12's starter kits with Shadcn, powered by Laravext's file-based routing system, for those who enjoy building your application in the "traditional API way".
Check out the video: https://youtu.be/wrhCLKdYgIE
or the docs at https://laravext.dev
or maybe my first post about Laravext in this subreddit: https://www.reddit.com/r/laravel/comments/1ewnfd3/im\_happy\_and\_nervous\_to\_announce\_my\_first\_and/?utm\_source=share&utm\_medium=web3x&utm\_name=web3xcss&utm\_term=1&utm\_content=share\_button
https://redd.it/1j6nsew
@r_php
I'm happy to announce the new Laravext Starter Kits, based on Laravel 12's starter kits with Shadcn, powered by Laravext's file-based routing system, for those who enjoy building your application in the "traditional API way".
Check out the video: https://youtu.be/wrhCLKdYgIE
or the docs at https://laravext.dev
or maybe my first post about Laravext in this subreddit: https://www.reddit.com/r/laravel/comments/1ewnfd3/im\_happy\_and\_nervous\_to\_announce\_my\_first\_and/?utm\_source=share&utm\_medium=web3x&utm\_name=web3xcss&utm\_term=1&utm\_content=share\_button
https://redd.it/1j6nsew
@r_php
YouTube
Laravext Starter Kits for Laravel 12 (with Shadcn)
This is the introduction to Laravext's new starter kits that use Laravel 12 and Shadcn, which are based on Laravel 12's new starter kits.
For more details, check the documentation at:
https://laravext.dev
#laravel #laravext #vue #react #nextjs #inertiajs…
For more details, check the documentation at:
https://laravext.dev
#laravel #laravext #vue #react #nextjs #inertiajs…
A humble request (Part 1) - Symfony vs Laravel
https://medium.com/@paulclegg_18914/symfony-vs-laravel-a-humble-request-part-1-412f41458b4f
https://redd.it/1j6sjib
@r_php
https://medium.com/@paulclegg_18914/symfony-vs-laravel-a-humble-request-part-1-412f41458b4f
https://redd.it/1j6sjib
@r_php
Medium
Symfony vs Laravel: A humble request (Part 1)
If you’re reading this article you’ve likely already heard of Symfony and Laravel.
Regexp class in SPL
Anyone else ever lament that PHP doesn't have a
Instead, we always have to deal with patterns as strings, which can be annoying:
It would be especially helpful in configuration, where there can often be something like
Woudln't it be great if there were a SPL
Curiously, `RegexIterator` exists, but not something simpler for a single expression.
https://redd.it/1j6n2wc
@r_php
Anyone else ever lament that PHP doesn't have a
Regexp class in its std lib (e.g. Ruby, JS) to represent a regular expression and associated flags?Instead, we always have to deal with patterns as strings, which can be annoying:
It would be especially helpful in configuration, where there can often be something like
MyConfig::$match: string that can be handled as an exact match or regex pattern. With them both as strings, we often have to resort to additional configuration, e.g. MyConfig::$exactMatch: bool. And even with that, it doesn't provide anywhere to configure regex flags.Woudln't it be great if there were a SPL
Regexp object, so we could just have MyConfig::$pattern: string|\Regexp?Curiously, `RegexIterator` exists, but not something simpler for a single expression.
https://redd.it/1j6n2wc
@r_php
A Week of Symfony #949 (3-9 March 2025)
https://symfony.com/blog/a-week-of-symfony-949-3-9-march-2025?utm_source=Symfony%20Blog%20Feed&utm_medium=feed
https://redd.it/1j73nye
@r_php
https://symfony.com/blog/a-week-of-symfony-949-3-9-march-2025?utm_source=Symfony%20Blog%20Feed&utm_medium=feed
https://redd.it/1j73nye
@r_php
Symfony
A Week of Symfony #949 (March 3–9, 2025) (Symfony Blog)
This week, the upcoming Symfony 7.3 version renamed the JsonEncoder component to JsonStreamer, added support for Valkey schemes in the Cache component and introduced a field_id() form helper.
What do you think about this 8 hour long Laravel "ad"?
https://www.youtube.com/watch?v=a1cWkClBXLI
https://redd.it/1j74blv
@r_php
https://www.youtube.com/watch?v=a1cWkClBXLI
https://redd.it/1j74blv
@r_php
YouTube
Launching a site in one day... WITH PHP?
Twitch https://twitch.tv/ThePrimeagen
Discord https://discord.gg/ThePrimeagen
Laravel Cloud is a great way to actually ship something (not that we would know) - Check out this awesome way to ship ship ship! lrvl.co/topshelf
Sentry is a great way to track…
Discord https://discord.gg/ThePrimeagen
Laravel Cloud is a great way to actually ship something (not that we would know) - Check out this awesome way to ship ship ship! lrvl.co/topshelf
Sentry is a great way to track…