steveryan
How to make IEx print strings instead of charlists
Hi , Trying to understand why
Phoenix.HTML.Link.link("Home", to: '/')
is returning
{:safe, [60, "a", [[32, "href", 61, 34, "/", 34]], 62, "Home", 60, 47, "a", 62]}
instead of
{:safe, ["<a href=\"/\">", "Home", "</a>"]}
like I would expect.
I’m gathering that it’s showing the char codes, but also the nested arrays are throwing me off too.
Thanks for the help!
Steve
Marked As Solved
kokolegorille
Hello and welcome,
It is because Phoenix templates use IO list for optimization…
See this post for more information.
https://www.bignerdranch.com/blog/elixir-and-io-lists-part-1-building-output-efficiently/
Also Liked
Nicd
Note that single quotes are for charlists. So the '/' you are passing in is not a string but a charlist. It’s a bit odd that it works at all, but when interfacing with Elixir libraries you should use double quoted string literals.
dimitarvp
You can use just to_string btw.
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
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










