Hacker News new | past | comments | ask | show | jobs | submit login

You’re right about batteries not included in Phoenix. The jinja2 extends sounds a bit terrifying to me.. Not only do you have to deal with figuring out Python class inheritance you have to figure out template ones in a pseudo-language?! It doesn’t look as bad as I feared but still [1]. Despite that I made a recent comment on HN regarding Jinja templates [2]. EEx looks basic but since Elixir is functional the templates are pretty powerful. I’m working on a LiveView wrapper for Bulma, which essentially needs “blocks” and was pleasantly surprised how easy it was to embed multiple layers of templates and it mostly Just Worked(tm) [3]. That was amazing to me! No need to deal with extra pseudo language inheritance. I'd like to use macros to simplify specifying child blocks and provide compile time check of block types, but I’ve got work todo.

1: https://flask.palletsprojects.com/en/1.1.x/patterns/template... 2: https://news.ycombinator.com/item?id=22746088 3: https://github.com/elcritch/bulma_widgets




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!


> Phoenix view/layout things still confuse me.

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...




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: