gpt4 book ai didi

ruby - 在 Padrino application.haml 模板中选择性地使用 yield_content

转载 作者:数据小太阳 更新时间:2023-10-29 08:40:27 24 4
gpt4 key购买 nike

在基于 Haml 的 Padrino 解决方案中,我有一个像这样的 application.haml:

!!!
%html
%head
%title "blah"
%body
#header
= yield_content :headcontent
#container
...

对于 :headcontent,在我的页面中(例如 index.haml)我有

- content_for :headcontent do
#headcontent
%h2= "Index header stuff"
#content
...

我想做的是让像 index.haml 这样的内容页面可以可选地指定 - :headcontent 的内容。那就是我希望 application.haml 包含一些 default :headcontent 只有当页面不执行 - content for :headcontent.

我该怎么做?

最佳答案

在您的主文件中,您应该能够使用 content_for?,如下所示:

- if content_for?(:headcontent)
= yield_content :headcontent
- else
something else

关于ruby - 在 Padrino application.haml 模板中选择性地使用 yield_content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8126895/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com