zimt28

zimt28

LiveView: Use render/1 alongside template file

Hello, I’m currently trying LiveView Native and would like to keep my html template file alongside the custom render(%{format: :swiftui} = assigns) function. I’ve found a way but I feel like there must be an easier option like a super(assigns) call or similar:

defmodule AppWeb.WelcomeLive do
  @moduledoc false

  use AppWeb, :live_view
  use LiveViewNative.LiveView

  require Phoenix.LiveView.HTMLEngine

  @impl true
  def render(%{format: :swiftui} = assigns) do
    ~SWIFTUI"""
    <VStack>
      <Text>App</Text>
    </VStack>
    """
  end

  def render(assigns) do
    Phoenix.LiveView.HTMLEngine.compile("lib/app_web/live/welcome_live.html.heex")
  end
end

Is there a more elegant way to do this?

Marked As Solved

rcm765

rcm765

For v0.3, currently beta is v0.2, we’ll be introducing tighter integration with Phoenix and LiveView taking advantage of the recently added render_with/1 function. I’ve been refactoring LVN around this over the past week and after numerous discussions with Jose it looks like the future of LVN will to push for render module isolation. Meaning the LiveView will handle html and the events but for other formats like swiftui and jetpack these will be rendering from their own module. I’ve already got this working in a local branch and will be pushing it up to main once v0.2 goes final around mid-January. This gets you what you want as in LV itself it detects the existence of render/1 to determine if it uses a template file or not. Because in our currently implementation of LVN we overload the render/1 function we cannot support a mix of some LVN render functions and html template files. But for v0.3 with the rendering for each format being in its own module this will no longer be a problem.

Where Next?

Popular in Questions Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement