I know "template inheritance" sounds horrible because of the name and the abuse of the concept in some oo languages ... especially discussed here in the context of a functional language ;) ... but I can really testify that extends&blocks work WAY WAY better than the traditional includes, especially for the layout level (by the way, you can still do includes when it makes sense).
Currently I'm doing a LiveView project where I have two layouts and a mix of traditional and LV pages. It really feels non-optimal to me to have to create plug pipelines just to use some put_*_layout() plugs.
I'm not even sure it should be a concern at the router level, whereas I could have just declare in each template the layout I wanted (extends) and/or use the three-level model, cf https://symfony.com/doc/3.4/templating/inheritance.html
I checked your library, I haven't tried LiveView components yet though, I only read the docs.
That symfony case makes a bit more sense. Especially in the context of views and layouts. Phoenix view/layout things still confuse me. Never tried learning them so I’ve got one global layout view setup on Bulma (or Bootstrap). It works as I’m doing more of an SPA style UI. I set a title using the controller which feels klunky too, like the put_*_layout setup.
Given Elixir templates are functional you probably could create a view “template inheritance” with a single macro. My Bulma library is intended to be pretty basic, but hopefully you see it’s easy to pass an case with sub-blocks.
I wonder if setting up a macro that could take named blocks and inject them into an EEx template might work for your case of including a view-template in a template. That’d be similar to what I’d like in my library, as it’d be nice to remove the extra “case / block” and just have a “template MyProject.Template, do :header -> <H1>Title</H1> end“. Bonus would be that approach would check block names at compile time! Also you should checkout live components. They’re handy for widgets!
When I worked through the Programming Phoenix book, for some reason the view/layout thing was what I struggled with most, and even in the years since its only been recently that I feel I have a proper 'grasp' of how it works.
I've been scratching my head as to why this, of all things Phoenix, has been tripping me up so much. Maybe it's right at the 'sweet' spot between Rails magic and (often) Phoenix explicitness, while also being the kind of thing that I find myself least interested in 'grokking'?
> Maybe it's right at the 'sweet' spot between Rails magic and (often) Phoenix explicitness, while also being the kind of thing that I find myself least interested in 'grokking'?
Think you nailed it on the head! It's a chore, and there's a bit of implicitness / Rails-style magic involved. Not much mind you, but the implicit naming thing trips me up.
I suppose the good part of the experience is that it taught me, once again, that as soon as I run into issues I should probably go read the docs until I properly understand things, rather than tweak things for a while until they magically work and then move on...
Currently I'm doing a LiveView project where I have two layouts and a mix of traditional and LV pages. It really feels non-optimal to me to have to create plug pipelines just to use some put_*_layout() plugs.
I'm not even sure it should be a concern at the router level, whereas I could have just declare in each template the layout I wanted (extends) and/or use the three-level model, cf https://symfony.com/doc/3.4/templating/inheritance.html
I checked your library, I haven't tried LiveView components yet though, I only read the docs.