

I usually call mine ComponentViewĪnd use it inside any of my templates, for example:Ĭomponent.primary_button("My Link", to: "yadayada"). Module that encapsulates your HTML helpers. Helpers are used across multiple views and are generic, you can create a plain Remember that you can create shared Views. html.leexĮxtension so the LiveView rendering engine kicks in. Still work just remember to keep the html file named with an. Implement your own render(assigns) that calls Move your my_ file to the standard Phoenix locations (ie, Separate from business logic in the LiveView:Īdd your own standard Phoenix view MyView (or a better name). If you have a LiveView with lots of HTML helper functions that you want to LiveView placement, and put your my_live.ex and my_ next toĮach other under lib/my_app_web/live. If you have a LiveView with lots of HTML, then you should use the standard

If you have a simple LiveView, then you can implement render(assigns)Īnd inline your html with the ~L sigil. my_ = The template rendered by MyLive or MyView.

#Phoenix liveview examples code#
This shouldĪll of these strategies work, this is purely about opinionated code organizing,īut who doesn’t love reading opinions? Plus we’ll learn how the views are I want to show you a couple different View-rendering strategies. Phoenix and Phoenix LiveView renders templates. Today, that concept that cemented in my mind is how I hope to open-source this soon when it’s ready.Įverytime I build one, I learn something new and find a new pattern, and someĬoncept finally clicks. I’ve written a couple LiveView applications now,Ī request logger, much like Phoenix Live Dashboard‘sĪn internal webmail server, for me to receive and send email through
