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

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews