更改模板布局的正确/最简单方法是在每个Controller操作中使用private void processFolder (PSTFolder folder) throws PSTException, IOException {
if( folder.getUnreadCount() > 0){
PSTMessage email = (PSTMessage)folder.getNextChild();
while ( email != null && email.isRead() ) {
printDepth();
System.out.println("Email: " + email.getSubject());
email = (PSTMessage)folder.getNextChild();
}
if(email != null){
System.out.println("Email: " + email.getSubject());
saveAttachments(email);
/* here is where I need to mark this particualry mail as Read */
}
}
}
方法吗?想要为不同控制器设置不同布局的一个简单示例似乎变得非常重复(下面),所以感觉我在框架内缺少某些东西。
put_layout
答案 0 :(得分:18)
我认为通过设置默认布局可能是最好的。
defmodule MyPhoenix.AController do
use MyPhoenix.Web, :controller
plug :put_layout, "LayoutA.html"
def pageOne(conn, _params) do
render conn, "page1.html"
end
def pageTwo(conn, _params) do
render conn, "page2.html"
end
end
defmodule MyPhoenix.BController do
use MyPhoenix.Web, :controller
plug :put_layout, "LayoutB.html"
def pageOne(conn, _params) do
render conn, "page1.html"
end
def pageTwo(conn, _params) do
render conn, "page2.html"
end
end
答案 1 :(得分:12)
例如,如果您需要一个不同的布局来说明路由器中单独的管道管道覆盖的所有管理控制器,您可以为管道管道指定plug :put_layout, {MyApp.LayoutView, :admin}
。我是从http://www.cultivatehq.com/posts/how-to-set-different-layouts-in-phoenix/学到的。