如何在 Sinatra 中制作布局模板?

发布于 2024-10-03 01:05:51 字数 216 浏览 0 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉生梦死 2024-10-10 01:05:51

自动包装

要使每个视图默认包装在布局中,请在 views/layout.haml 中创建一个文件,并且您对 haml :myview 的调用将自动包装在该布局中布局。

跳过布局

如果您希望特定视图渲染不使用该布局,请使用:

get '/' do
   # Other pages will use layout.haml, but not the main page
   haml :home, :layout => false
end

使用不同的布局

如果您想使用通用布局以外的布局,请创建另一个文件(例如 views/admin_layout.haml< /code>) 然后将其作为选项传递:

get '/admin/create' do
   haml :create, :layout => :admin_layout
end

Automatic Wrapping

To make every view default to be wrapped in a layout, create a file in views/layout.haml and your calls to haml :myview will automatically be wrapped in this layout.

Skipping the Layout

If you want a particular view rendering not to use the layout, use:

get '/' do
   # Other pages will use layout.haml, but not the main page
   haml :home, :layout => false
end

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:

get '/admin/create' do
   haml :create, :layout => :admin_layout
end
埖埖迣鎅 2024-10-10 01:05:51

如果您还没有,请创建一个名为...的文件夹

views/

,将您的布局放入其中,调用您的布局

layout.haml

或您想要使用的任何扩展名(例如 .erubis) 。

If you haven't already, create a folder where your sinatra script lives called...

views/

and put your layout in there, call your layout

layout.haml

or whatever extension (e.g. .erubis) you'd like to use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文