开发者

Nested ERB template layouts like Liquid?

开发者 https://www.devze.com 2023-02-02 06:46 出处:网络
With Liquid, you can nest layouts. E.g., my site\'s default layout builds off of the base layout. Is this possible with ERB? If so, how?

With Liquid, you can nest layouts. E.g., my site's default layout builds off of the base layout.

Is this possible with ERB? If so, how?

I'm asking because I'm migrati开发者_开发知识库ng a GitHub Pages site to Sinatra, so that I can handle forms natively (not with Wufoo or Google Forms).


try this:

make a file called layout.haml (or erb or whatever your templates are in), and put it in the views folder. this is your site layout, and it could look like this (I'm using haml):

 %html
  %head 
    %link(rel="stylesheet" type="text/css" href="style.css")  
  %body
    %div.outer
      %div.inner
        = yield

the magic part is the =yield this is where Sinatra will render whatever template you call in your route. the = tells your template to expect ruby code.

for example, if your route is

get '/' do 
  haml :index
end

then your template at /views/index.haml will be inserted. you can also use a custom layout if you tell your template to override the one at /views/layout.haml.

hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号