如何在phoenix框架中提供静态页面? [英] How to serve static page in phoenix framework?
问题描述
我想在Phoenix Framework中提供静态页面,以便在Angular Views中使用它.我知道我可以提供常规HTML,但是我想摆脱默认的LayoutView
.我可以采用一种解决方案,使其仅具有一些不从LayoutView
继承"的Phoenix View.有可能吗?
I want to serve static page in Phoenix Framework to use it in Angular Views. I know I can serve regular HTML, but I want to get rid of the default LayoutView
. I could do with a solution to just have some Phoenix Views which don't "inherit" from LayoutView
. Is it possible?
推荐答案
您可以通过在priv/static
中具有文件并在Plug.Static
选项中匹配路径来提供静态文件:
You can serve static files by having a file in priv/static
and matching the path in the Plug.Static
options:
plug Plug.Static,
at: "/", from: :hello_phoenix, gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt my_fine.html)
您还可以使用 put_layout/2 绕过布局:
You can also bypass the layout using put_layout/2:
conn
|> put_layout(false)
|> render("index.html")
put_layout/2
函数也可以作为插件调用(由于函数参数).如果您希望将其应用于整个控制器,这将很有用:
The put_layout/2
function can also be called as a plug (due to the function arguments). This is useful if you want it to apply to the entire controller:
plug :put_layout, false
这篇关于如何在phoenix框架中提供静态页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!