Add Facebook Open Graph tags to Phoenix Framework web page

Hi there,

This is very easy:

1. Create a function in LayoutView web/views/layout_view.ex:

Here I was using content_tag function but it created closed </meta> tag which I don’t really like.
In the else clause you can put some default OG tags, I put only fb:app_id fir the start.

2. Add this function to the app layout template web/templates/layout/app.html.eex:

Where assigns is the map which contains almost everything you need to render the view.

3. Update your controller function with OG tags tuple and pass it to template like this:

I guess the code here is self-explanatory (I used code from my pet-project www.instadreams.com).
If you have some thought how we can improve the code above feel free to post a comment here 🙂

Deploy Phoenix/Elixir project issue: npm ERR! TypeError: Object.keys called on non-object

When you deploy you phoenix/elixir project on production and something goes wrong it is very useful to make a git clone of your project directly on production server and try to run it there via iex -S mix to see what’s wrong. This is actually no really good practice but one of the fastest options.
Continue reading “Deploy Phoenix/Elixir project issue: npm ERR! TypeError: Object.keys called on non-object”