asnyder002

asnyder002

Do Surface components need to be injected into Surface Live View?

I am taking a look at Surface UI to build out components. From my understanding you can build out Surface.Component modules and then using a Surface.LiveView wrapper inject the components into the render function. Is there a way to create a component and then use it in a traditional template somehow?

For example if I have an index page already created and built out a search/filter component, is there a way for me to render <SearchBar/> ?

Marked As Solved

msaraiva

msaraiva

Broadway Core Team

Hi @asnyder002!

A Surface component is also a LiveComponent so, most of the time, you can use live_component/3 just like you would do for any other component:

<%= live_component @socket, SearchBar, id: "search_bar", ... %>

The exceptions are:

  1. You need to retrieve context assigns inside your component
  2. You’re using named slots in your component

Phoenix LV has no built-in support for contexts nor named slots, so if you need them, you’ll have to move your code to render/2 and use ~H or wait a bit until Support loading external templates and css files · Issue #22 · surface-ui/surface · GitHub is done and convert your eex template into a .sface file.

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
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
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
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
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement