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?

First 10 of 10 Posts Switch mode

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_homed_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
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement