shahryarjb
How to write elixir code in html(Phoenix)
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?
Marked As Solved
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", [
]}
]
Also Liked
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) %>.
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.
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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex










