niccolox

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

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

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?

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

We're in Beta

About us Mission Statement