fabioticconi

fabioticconi

Using variables from for loop into tags

Hi,

I’d like to do something like this linreg/lib/linreg_web/live/regression_live.html.leex at master · Tmw/linreg · GitHub but its syntax is deprecated in the latest Phoenix.

This:

<svg width="800" height="800">
    <%= for {x,y} <- @points do %>
      <circle cx="{x}" cy="{y}" r="15" fill="#24DA5E" />
    <% end %>
</svg>

Simply gets me the following into the page source:

  <svg width="800" height="800">
      <circle cx="{x}" cy="{y}" r="15" fill="#24DA5E"></circle>
      <circle cx="{x}" cy="{y}" r="15" fill="#24DA5E"></circle>
      <circle cx="{x}" cy="{y}" r="15" fill="#24DA5E"></circle>
      <circle cx="{x}" cy="{y}" r="15" fill="#24DA5E"></circle>
      <circle cx="{x}" cy="{y}" r="15" fill="#24DA5E"></circle>
  </svg>

I’ve tried to use <%= x %> but Phoenix tells me to use {} instead. I’m not really sure how to get the framework to convert my x and y variables (they are floats) to their values.

Can anyone point me in the right direction?

For reference, this is the content of the points list of tuples before being passed to render:

[
  {10986.666666666666, -1606.2400000000002},
  {10213.333333333334, -1609.2800000000002},
  {18666.666666666664, -3199.44},
  {36533.33333333333, -7131.12},
  {56293.33333333333, -11265.36}
]

Marked As Solved

stefanchrobot

stefanchrobot

This should work:

<svg width="800" height="800">
    <%= for {x,y} <- @points do %>
      <circle cx={x} cy={y} r="15" fill="#24DA5E" />
    <% end %>
</svg>

Also Liked

fabioticconi

fabioticconi

Oh my.. I guess it’s time to go to bed :sweat_smile: thank you @stefanchrobot

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
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
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
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
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
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
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
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
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 records...
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
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
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

We're in Beta

About us Mission Statement