shahryarjb

shahryarjb

Hello, Every sample shows me like this:

<p><%= handler_info @conn %></p>

but I need this:

<p class="<%= handler_info @conn %>">test</p>

when I want to use it , I have an error. if I use Tag or raw, my html template is confused.

how can I use like that?

Showing Posts 1 to 10

idi527

idi527

:waving_hand:

What’s the final HTML that you want?

<p class="???">test</p>

What does handler_info(@conn) return?

shahryarjb

shahryarjb OP

for example:

name_of_class = Db.classname

<p class="<%= name_of_class%>">test</p>

after compile:

<p class="drag test cg">test</p>

I have written handler_info(@conn) for example not real code. would you mind seeing the above code again, Please?

idi527

idi527

name_of_class = Db.classname()

<p class="<%= name_of_class %>">test</p>

would work fine, I think, if Db.classname() returns "drag test cg". But it wouldn’t be replaced during compilation, though. For that you’d need to either use macros or hard code the value. Since it’s a function call, it would be replaced every time the template is rendered.

shahryarjb

shahryarjb OP

Hmm,

Please see the code :

<%= Enum.sort(menu) |> Enum.each( %>
  <div class="dropdown-menu" aria-labelledby="navbarDropdown">
    DEV
  </div>
<% ) %>

I want to use Enum.each instead of for loop like this , but I have an error :

for loop works me but enum.each not :

idi527

idi527

Try using Enum.map instead. Enum.each doesn’t have any output, so that’s why it doesn’t work. for comprehensions and Enum.map would work similarly in your case.

shahryarjb

shahryarjb OP

in Enum.map I also have this problem, I think because ‘)’

like :

 <%= Enum.map(menu, fn({_key, {name, addres, sub}}) -> %>
        <div class="basket">
        <div class="container">
 <%= end) |> Enum.sort %>
idi527

idi527

in Enum.map I also have this problem

What problem?


Try this

<%= Enum.map(menu, fn {_key, {name, address, sub}} -> %>
  <div class="basket"></div>
  <div class="container"></div>
<% end) %>

Does it work?

Note that there is no = in <% end) %>.

shahryarjb

shahryarjb OP

errors:

== Compilation error in file lib/trangell_html_site_web/views/layout_view.ex ==
** (SyntaxError) lib/trangell_html_site_web/templates/layout/_navigation.html.eex:67: unexpected token: )
    (eex) lib/eex/compiler.ex:45: EEx.Compiler.generate_buffer/4
    (eex) lib/eex/compiler.ex:54: EEx.Compiler.generate_buffer/4
    (phoenix) lib/phoenix/template.ex:378: Phoenix.Template.compile/2
    (phoenix) lib/phoenix/template.ex:186: anonymous fn/3 in Phoenix.Template."MACRO-__before_compile__"/2
    (elixir) lib/enum.ex:1899: Enum."-reduce/3-lists^foldl/2-0-"/3
    (phoenix) expanding macro: Phoenix.Template.__before_compile__/1
    lib/trangell_html_site_web/views/layout_view.ex:1: TrangellHtmlSiteWeb.LayoutView (module)
    (elixir) lib/kernel/parallel_compiler.ex:198: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6
```

your code works!!
shahryarjb

shahryarjb OP

but how can I sort? by they position ?

my map :

def main_menu do
    menu = %{
      a_home: {"خدمات", "/", [
          {"ops1", "/sup1"}, {"test1", "/sup2"}, {"test2", "/sup3"}
        ]},
      b_blog: {"بلاگ", "/blog", [
          {"ops2", "/sup1"}, {"test3", "/sup2"}, {"test4", "/sup3"}
        ]},
      c_about: {"درباره ما", "/about", [
        ]},
      d_contact: {"ارتباط با ما", "/contact", [

        ]}
    }

I need it to load like this :

a_home …d_contact but if I remove a form a_home , it will load

b_blog
c_about
d_contact
home

but home should be loaded at first.

idi527

idi527

If you need order, maybe try storing it in a list:

def main_menu do
    menu = [
      home: {"خدمات", "/", [
          {"ops1", "/sup1"}, {"test1", "/sup2"}, {"test2", "/sup3"}
        ]},
      blog: {"بلاگ", "/blog", [
          {"ops2", "/sup1"}, {"test3", "/sup2"}, {"test4", "/sup3"}
        ]},
      about: {"درباره ما", "/about", [
        ]},
      contact: {"ارتباط با ما", "/contact", [

        ]}
    ]
— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
csmr
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley: Mutonex gamedesign was finish...
New
Stef-Verniers
Hello I’ve been coding in Elixir for almost two years now because of my current job where we implemented Elixir in our application. But ...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
kip
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews