Template partials best practices

I’m curious what everyone is doing to organize and break large complex templates into smaller parts. I have a complex page layout, and I want to break the layout into discrete parts rather than have one very large template partial.

Should I just create several template partials under /partials folder for each section of the page template? Or, create a subfolder in /partials specific to this page template? I’m curious as to what others are doing and what the best practice for this is.

[edit: grammar]

If you’re using Sage 9, I’m still waiting for a reply/update, but you can see my new issue here with Blade now having @component support.

With this new addition, I plan on creating a templates/components folder and using it for things such as alerts as well as converting large partials into multiple small components to use inside of the partial instead.

I can see this being great for things like sliders, widgets, etc. and should help a bit with organization.

Components can also accept data in the form of an array or as a @slot which should make them quite useful.

You can read more about Blade Components here.

1 Like

Do note that Sage 9 doesn’t support @component yet: https://github.com/roots/sage/issues/1841

Sage is a starter theme, though. It doesn’t support @component out of the box but updating composer.json to include new features is right in line with Sage’s intended use.

2 Likes