如何在 Sinatra 中制作布局模板?
我是 Sinatra 的新手,我不知道将我的应用程序布局放在哪里。
内联方法
# app code
__END__
@@layout
%html
= yield
我已经看到使用但我希望布局位于它自己的 .haml
文件中的
。布局文件应该命名为什么?应该放在什么目录下?
I'm new to Sinatra and I can't figure out where to put my application layout.
I've seen the inline method that uses
# app code
__END__
@@layout
%html
= yield
But I'd like the layout to be in it's own .haml
file.
What should the layout file be named? What directory should it be placed in?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
自动包装
要使每个视图默认包装在布局中,请在
views/layout.haml
中创建一个文件,并且您对haml :myview
的调用将自动包装在该布局中布局。跳过布局
如果您希望特定视图渲染不使用该布局,请使用:
使用不同的布局
如果您想使用通用布局以外的布局,请创建另一个文件(例如
views/admin_layout.haml< /code>) 然后将其作为选项传递:
Automatic Wrapping
To make every view default to be wrapped in a layout, create a file in
views/layout.haml
and your calls tohaml :myview
will automatically be wrapped in this layout.Skipping the Layout
If you want a particular view rendering not to use the layout, use:
Using a Different Layout
If you want to use a layout other than the common layout, create another file (for example
views/admin_layout.haml
) and then pass this as an option:如果您还没有,请创建一个名为...的文件夹
,将您的布局放入其中,调用您的布局
或您想要使用的任何扩展名(例如
.erubis
) 。If you haven't already, create a folder where your sinatra script lives called...
and put your layout in there, call your layout
or whatever extension (e.g.
.erubis
) you'd like to use.