tduccuong

tduccuong

SurfaceUI render separate template file

Hi, I am trying out SurfaceUI now. It is a fresh LiveView 0.16 project. Within my lib/live/page_live.ex, I have:

@impl true
def render(assigns) do
  Phoenix.View.render(PageView, "index.html", assigns)
end

where lib/templates/page/index.html.heex has this content:

<h1 class="text-red-500 text-3xl font-bold text-center">
  Welcome!
</h1>
<Hello />

I get this error when compiling:

** (MatchError) no match of right hand side value: {:tag_open, "Hello", [], %{column: 1, line: 4, self_close: true}}
    (phoenix_live_view 0.16.4) lib/phoenix_live_view/html_engine.ex:483: Phoenix.LiveView.HTMLEngine.decompose_remote_component_tag!/3

Everything is OK if I use the F sigil inside page_live.ex:

@impl true
  def render(assigns) do
    ~F"""
    <h1 class="text-red-500 text-3xl font-bold text-center">
      Welcome!
    </h1>
    <Hello />
    """
  end

What is the best practice that you guys recommend me in this case?

Thanks a lot!

Marked As Solved

moogle19

moogle19

I think Phoenix.View.render doesn’t work with Surface.
I would just colocate the template file (move it to lib/live/page_live.sface) and remove render/1 from page_live.ex altogether (see Colocated Templates).

Also Liked

tduccuong

tduccuong

That works, although I guess I will have to familiarize myself with this new way of organizing code.

Thanks a lot!

Where Next?

Popular in Questions Top

New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
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
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Other popular topics Top

peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement