Last active
April 25, 2016 06:52
-
-
Save pikender/c84672d42558ac731eddd77e338ec1da to your computer and use it in GitHub Desktop.
Defining Phoenix Template Path Fallback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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