Symfony + Stimulus + Turbo
Hello
I'm testing the Symfony theme version, and I would like to ask if it is possible to use Turbo with it. If so, could you send me documentation or feedback about the kt-app JavaScript conflict?.
When I installed Turbo, after the first page reload, the kt-app JavaScript stopped working.
Thank you in advance for reply.
Best regards,
Tania
Replies (3)
Hi Tania.
Sorry for the delay.
Turbo Drive changes how page navigation works - instead of full page reloads, it uses AJAX to fetch new pages and replaces just the <body> content.
This conflicts with the KT theme's initialization process because:
- KT components initialize on DOMContentLoaded or load events
- When Turbo navigates, these events aren't fired again
- Theme components that expect a full page reload aren't being properly re-initialized
Could you please try these steps:
- Uncomment and modify the attributes in your webpack_encore.yaml:
- Enable Webpack Encore in your templates, in layout/master.html.twig, uncomment these lines:
- Create a Stimulus controller to handle KT initialization
- Add Turbo-specific code in your app.js
- Apply the controller to your layout
Metronic has custom page loaders that might conflict with Turbo. You may need to modify how they work:
<pre> // Adjust to work with Turbo document.addEventListener('turbo:before-visit', () => { if (window.KTApp && typeof window.KTApp.showPageLoading === 'function') { window.KTApp.showPageLoading(); } }); document.addEventListener('turbo:render', () => { if (window.KTApp && typeof window.KTApp.hidePageLoading === 'function') { window.KTApp.hidePageLoading(); } }); </pre>More info: Hotwired Turbo Handbook Symfony UX Turbo Integrating Turbo with existing JavaScript
Hi,
Are you referring to Metronic 9 Tailwind or Metronic 8 Bootstrap ?
Regards,
Sean