Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Layouts & Components with AlpineJS

Tags:

alpine.js

I am wondering -- is there a way to create layouts and/or components with AlpineJS (so that I can keep my code DRY)? If not, are there any solutions that integrate with AlpineJS that add this functionality (without having to resort to a full framework like React or Vue)?

like image 469
Moshe Avatar asked Sep 19 '25 01:09

Moshe


1 Answers

Alpine.js tries to avoid templating as much as possible since it's designed to work in tandem with server-side templating or a static side generator.

The example per the Alpine.js docs to load HTML partials is to use x-init="fetch('/path/to/my/file.html).then(r => r.text()).then(html => $refs.someRef.innerHTML = html)" (x-init is just one spot where this could be done).

like image 173
Hugo Avatar answered Sep 22 '25 18:09

Hugo