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

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
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
Kagamiiiii
Student &amp; New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
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
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
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
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
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
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
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New

We're in Beta

About us Mission Statement