【发布时间】:2015-07-29 05:55:25
【问题描述】:
我想知道是否有办法将动态命名内容从布局传递到页面。
例如,
布局
<body>
<div class="container">
{{ content }}
</div>
<footer>
<p>© Company 2015</p>
</footer>
<script src="path/to/jquery.js"></script>
{{ page.other_content }}<!-- Objective: To write scripts that varies with page -->
</body>
页面
---
layout: default
title: About Us Page
---
<p> This is about us page </p>
{% capture other_content %}
<script>
$(document).ready(function(){
console.log("About us page.");
});
</script>
{% endcapture %}
有没有办法从布局中呈现页面中的多个内容部分?
在 ASP.NET 中我们可以做到这一点的是 Layout 页面。
@RenderSection("scripts", required: false)
在内容页面中,我们可以像这样呈现该部分。
@section scripts {
Hey I'm actually on the _Main layout.
I can vary according to the page.
My presence is not mandatory in every page
}
这可以用 jekyll 完成吗?
【问题讨论】:
-
您使用
capture的方法没问题。
标签: jekyll github-pages