Is it possible to create the ~L sigil’s contents in real-time based on the web site visitor? I’m new to Phoenix and LiveView and have been struggling to figure this out.
I’m looking for web app users to be able to design their own custom themes for their account. Each user will have a different LiveView template for any given page (i.e. everyone’s profile page may have different HTML/CSS even if the variables such as Username, Bio, etc. are the same).
My idea was to convert the template they design to a LiveView template which would be stored in a database and build a LiveView that checks who is logged in and then have the render function display the LiveView template assigned to the user. But I’ve been having trouble creating an ~L sigil from a variable. Maybe there is a better way to approach this?
Templates are converted to elixir code at compile time, so it’s not simply editable at runtime. There are means of compiling modules at runtime on the beam, but it’s not something easily supported out of the box and secondly a big security risk, as eex doesn’t do any kind of sandboxing. Your users could write any elixir code they wish in there.
You could allow users to edit parts of what a precompiled liveview renders, but this won’t be able to harness any of the optimizations done be liveview. Also for the templating part you’ll need a templating language, which is safe for that kind of usage, like liquid. EEx based templating is not meant for that.
Thanks, very helpful.
Yeah, I didn’t want to include any superfluous info but Liquid is exactly the method that I’ve been planning on using. Consequently, I’m not actually worried about the safety of running user templates. I figured I’d create custom tags to handle certain features that I’d want to use LiveView for (if it was possible).
That being said, it sounds like integrating Liquid with LiveView would be a bit of a challenge. It may be worth sticking to the more traditional Phoenix approach for this type of functionality.