Skip to content

Instantly share code, notes, and snippets.

@pikender
Last active April 25, 2016 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pikender/c84672d42558ac731eddd77e338ec1da to your computer and use it in GitHub Desktop.
Save pikender/c84672d42558ac731eddd77e338ec1da to your computer and use it in GitHub Desktop.
Defining Phoenix Template Path Fallback
# Refer https://github.com/phoenixframework/phoenix/blob/master/lib/phoenix/view.ex#L136
# For inspiration and implementation
defmodule Nectar.Web do
def view do
quote do
import unquote(__MODULE__), only: [template_root_folder: 1]
use Phoenix.View, root: template_root_folder(__MODULE__)
...
end
end
@priority_root "../templates/"
@default_root "lib/web/templates"
def template_root_folder(module) do
namespace =
module
|> Module.split
|> Enum.take(1)
|> Module.concat
priority_path =
Path.join(@priority_root, Phoenix.Template.module_to_template_root(module, namespace, "View"))
if File.exists? priority_path do
@priority_root
else
@default_root
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment