mbenatti
Concat Sigil ~E and others (how to)
Hello Guys, Elixir/phoenix have some helper to concat sigils?
What do you think about this feature?
Code:
defmodule Teste do
import Phoenix.HTML
def sigil_concat_1() do
~E"""
<div class="col-lg-4">
<%= "Hello" %>
</div>
"""
end
def sigil_concat_2() do
world = "World"
~E"""
<div class="col-lg-4">
<%= world %>!
</div>
"""
end
end
Test:
Interactive Elixir (1.5.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> s1 = Teste.sigil_concat_1
{:safe, [[["" | "<div class=\"col-lg-4\">\n "] | "Hello"] | "\n</div>\n"]}
iex(2)> s2 = Teste.sigil_concat_2
{:safe, [[["" | "<div class=\"col-lg-4\">\n "] | "World"] | "!\n</div>\n"]}
iex(3)> s1 <> s2
** (ArgumentError) argument error
iex(3)> s1 ++ s2
** (ArgumentError) argument error
:erlang.++({:safe, [[["" | "<div class=\"col-lg-4\">\n "] | "Hello"] | "\n</div>\n"]}, {:safe, [[["" | "<div class=\"col-lg-4\">\n "] | "World"] | "!\n</div>\n"]})
iex(3)>
Marked As Solved
NobbZ
sigil_e and sigil_E create some “safe” HTML strings. As long as you do further processing only in Phoenix.HTML one or more of the following should work:
e1 = ~E"stuff"
e2 = ~E"more stuff"
[e1|e2]
raw(safe_to_string(e1) <> safe_to_string(e2))
~e"#{e1}#{e2}"
3
Popular in Questions
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
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
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
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
Hi everyone,
I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
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
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
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
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
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
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









