#Rendering Phoenix Live Components from .html.leex files

3 messages · Page 1 of 1 (latest)

slow moon
#

Hello! I'm building a small project to learn Elixir/Phoenix and am using live components for some of the reusable aspects of the site. Right now, my live components look like the example below with all the HTML embedded in the .ex files using the ~H sigil. This is not great for readability especially when the HTML gets lengthy. Is there a way to pull this code out and define it in a .html.leex file instead? I've tried a few different approaches and examples online for normal components but haven't been able to get them working with live components. Thank you!

defmodule ExampleComponent do  
  use ProjectWeb, :live_component  

  def render(assigns) do    
    ~H"""
    HTML in here    
    """  
  end
end
wild fulcrum
#

remove the render callback and put a example_component.html.heex file in the same folder as the component module, then that will be used

slow moon
#

That was easy, thank you!