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_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

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
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
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

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
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews