Fl4m3Ph03n1x

Fl4m3Ph03n1x

How to replace deprecated ~E sigil with ~H in Phoenix render funciton

Background

In my quest to learn Phoenix LiveView I found myself using a render function that uses a deprecated sigil:

  def render(_assigns) do
    ~E"""
    <menubar>
      <menu label="<%= gettext "File" %>">
          <hr/>
          <item onclick="quit"><%= gettext "Quit" %></item>
      </menu>
      <menu label="<%= gettext "Extra" %>">
          <item onclick="browser"><%= gettext "Open Browser" %></item>
      </menu>
    </menubar>
    """
  end

Now, I understand this is a safe for to use eex code inside of Elixir. However the compiler says I should replace it with ~H. So my firs try is the following:

  def render(assigns) do
    ~H"""
    <menubar>
      <menu label="{@gettext('File')}">
          <hr/>
          <item onclick="quit"><%= gettext "Quit" %></item>
      </menu>
      <menu label="{@gettext 'Extra'}">
          <item onclick="browser"><%= gettext "Open Browser" %></item>
      </menu>
    </menubar>
    """
  end

Which does not work and does not show the text properly in the menu:

Quesion

What am I doing wrong?

Marked As Solved

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

I’m not sure why gettext has the @ infront of it. Did you try label={gettext("Extra")}?

Also Liked

Bumppoman

Bumppoman

The <% %> is not deprecated, it just can’t be used in tag attributes. It’s perfectly fine (and the only way) to use these to interpolate Elixir values into the HTML.

cblavier

cblavier

You should remove the extra double-quotes around braces.

<menu label={@gettext('File')}>

Where Next?

Popular in Questions Top

nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
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
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New

Other popular topics Top

skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
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 Postgres...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
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 52673 488
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127089 1222
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54120 245
New

We're in Beta

About us Mission Statement