niccolox
Eex if else for dev or prod with releases?
I read from here that MIX is not available in releases so code like this wont work in releases
<%= if Mix.env == :dev do %>
<a class="title" href="http://<%= post.website.dev_url %>/p/<%= post.id %>-<%= post.slug %>"><img class="card-img-top img-fluid" alt="<%= post.intro %>" src="<%= Application.fetch_env!(:arc, :primary) %><%= WwwSiteCom.Web.Blogs.Post.Image.url(post.filename, :card) %>"></a>
<% else %>
<a class="title" href="http://<%= post.website.domain %>/p/<%= post.id %>-<%= post.slug %>"><img class="card-img-top img-fluid" alt="<%= post.intro %>" src="<%= Application.fetch_env!(:arc, :primary) %><%= WwwSiteCom.Web.Blogs.Post.Image.url(post.filename, :card) %>"></a>
<% end %>
I read a stackoverflow about creating a macro but am wondering if there is any help on offer regarding a EEX example
ideally I want this switching, perhaps I need a function in a view?
Most Liked
Nicd
As mentioned, adding the domains to the config would be a good solution.
For things that don’t go cleanly into the config or where you need to run different code paths based on Mix env, I use this in my config.exs:
# Store mix env used to compile app, since Mix won't be available in release
config :code_stats, compile_env: Mix.env()
This way I can use Application.get_env(:code_stats, :compile_env) and it will work inside and outside releases, and will reflect the env the app was compiled with.
OvermindDL1
Can’t this just be replaced with this though?
<%= if unquote(Mix.env() == :dev) do %>
Still, testing specific environment names sounds like very poor form though, wouldn’t it be better to put a binding in a config file and just access that instead?







