mbenatti

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

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}"

Where Next?

Popular in Questions Top

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
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
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
fireproofsocks
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
komlanvi
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
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

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54006 488
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
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
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
stefanchrobot
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

We're in Beta

About us Mission Statement