[LiveComponent] Re-render via Mercure #3113
ytilotti
started this conversation in
RFC - Feature Ideas
Replies: 1 comment
-
I think it's possible to do something. An exemple of code: The broacast call: $this->hub->publish(new Update(
'/notifications',
TurboStream::update('#app-notifications', $this->componentRenderer->createAndRender('notifications')),
true
)); Twig use component: <div {{ turbo_stream_listen('notifications', 'default', { withCredentials: true }) }}>
<div id="app-notifications">
{{ component('notifications') }}
</div>
</div> TwigComponent: namespace App\Twig\Components;
use App\Entity\Notifications;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
use Symfony\UX\TwigComponent\Attribute\ExposeInTemplate;
#[AsTwigComponent(name: 'notifications', template: 'notifications.html.twig')]
class Notifications
{
public function __construct(
protected ManagerRegistry $em,
protected Security $security,
) {
}
#[ExposeInTemplate]
public function getNotifications(): array
{
return $this->em->getRepository(Notifications::class)->findAllUnreaded($this->security->getUser());
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to re-render via Turbo & Mercure?
I think can be a feature interesting to not rewrite code.
Maybe with the id and a refresh method Hotwire?
Beta Was this translation helpful? Give feedback.
All reactions