Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Custom Fonts in Phoenix

I'm trying to use a Custom Font in my Phoenix Application. I've placed them in the priv/static/fonts directory, and properly created and loaded the css file in web/templates/layout/app.html.eex template but they're not being served by the Phoenix Server.

/Users/Psycho/code/elixir/my_app/
▾ priv/
  ▸ repo/
  ▾ static/
    ▸ css/
    ▾ fonts/
      ▾ walsheim/
          gt-walsheim-light-web.svg
          gt-walsheim-light-web.eot
          gt-walsheim-light-web.ttf
          gt-walsheim-light-web.woff

The css file for sourcing the font:

// my_app/priv/css/fonts.css

@font-face {
    font-family: "Walsheim";
    font-style: normal;
    font-weight: 300;
    src:
        url("/fonts/walsheim/gt-walsheim-light-web.eot?#iefix") format("embedded-opentype"),
        url("/fonts/walsheim/gt-walsheim-light-web.woff") format("woff"),
        url("/fonts/walsheim/gt-walsheim-light-web.ttf") format("truetype"),
        url("/fonts/walsheim/gt-walsheim-light-web.svg#Walsheim") format("svg");
}
like image 453
Sheharyar Avatar asked Jul 12 '15 01:07

Sheharyar


People also ask

Can you use custom fonts in power apps?

Available Fonts To find the full list of custom fonts available for use in Power Apps there are a couple of techniques you can use. The fastest way is to search for 'Font Settings' in your Windows search bar. This will open up the Fonts menu. You can try any font name from this list to see if it works.

Can I use my own font on Shopify?

Use Any Font For Your Shopify StoreWith Fontify, you can use any font - both Google and Custom fonts! If you want to use customized fonts, just upload the font file and our app will do everything else. Our app will import any font you uploaded and process it to make it work in your store.

How do I add custom fonts to Xcode?

To add a font file to your Xcode project, select File > Add Files to “Your Project Name” from the menu bar, or drag the file from Finder and drop it into your Xcode project. You can add True Type Font (. ttf) and Open Type Font (. otf) files.


1 Answers

Okay, found the solution.

It looks like you have to tell phoenix which directories to serve for static files. I went in to my my_app/lib/my_app/endpoint.ex file and updated the Plug.Static plug to serve the fonts folder as well:

defmodule MyApp.Endpoint do
  use Phoenix.Endpoint, otp_app: :my_app

  plug Plug.Static,
    at: "/", from: :my_app, gzip: false,
    only: ~w(css images js fonts favicon.ico robots.txt)

  # Other Stuff ...
end

Source: PhoenixTalk - Serving static assets in a Sub-Folder other than the defaults

like image 184
Sheharyar Avatar answered Sep 19 '22 20:09

Sheharyar