-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot use some Phoenix helpers within curly braces #70
Comments
Since you're not really taking advantage of Surface (at from the example), have you tried using the Raw component? defmodule Foo do
use Surface.Component
import Phoenix.HTML.Link
alias Surface.Components.Raw
property(links, :list, default: ["foo", "bar", "baz"])
def render(assigns) do
~H"""
<div>
<#Raw>
<%= for l <- assigns[:links] do %>
<%= link to: "#" do %>
<span><%= l %></span>
<% end %>
<% end %>
</#Raw>
</div>
"""
end
end There is still the issue that Surface interpolates everything with |
@zamith This does get around it like manually using I guess I'm really just wondering if there is any compatibility between Surface and all the helpers we know and love. It seems the answer is yes with the use of |
Just like React, Surface cannot accept partial/incomplete expressions and probably never will since it has to generate a valid tree structure of the HTML/Components nodes at compile-time. So we can only accept complete expressions that can be be fully assigned to a particular node/attribute. I have some further comments about this here #23 (comment). In general, you should avoid having too much logic in your template. In case you do, and the available directives ( If for any particular reason you really need to use something like
|
I ran into this converting some partials into surface components. The complexity was just in creating a link using a do block so that some inner html could be set. My contrived example is just that, contrived, to illustrate it. I suppose it just means there should be another |
Exactly! Maybe we can come up with an alternative in the future to make this work somehow, but for now, our only options are: move to a separate function or create a wrapper component. The goal is to create builtin components for the most common helpers so we can provide a nice development experience.
No worries. That's why I'm here for :) I'm glad you're enjoying. |
@mathewdgardner feel free to bring any real case you already needed (like |
@msaraiva Good deal, I have several issues I've kept track of as I've learned how to use Surface. I can keep posting them in separate issues to keep them contained if they are welcome. I can also put together a PR for a link component. |
Awesome! PRs are always welcome! |
Cannot use Phoenix HTML helpers with do blocks with
{{ }}
.Environment
Contrived Example
With this we get a compiler warning and error
In this contrived example (intentionally not using the
:for
directive) we can move past the error by manually creating the anchor tag, but is this desired behavior?If we remove the
do
block forlink/2
we lose the error but keep the warning.Sorry @msaraiva, I don't mean to pummel you with issues. This is great package and I can't wait to see it reach v1.0.0!
The text was updated successfully, but these errors were encountered: