Permalink
Browse files

Fix layout front-matter variables rendering. #6071 (#6073)

Merge pull request 6073
  • Loading branch information...
ayastreb authored and jekyllbot committed Jun 14, 2017
1 parent c71c27a commit 2cfcb23a495372355ac2e7660e014fcbd129491c
Showing with 18 additions and 0 deletions.
  1. +9 −0 lib/jekyll/renderer.rb
  2. +3 −0 test/source/_layouts/default.html
  3. +2 −0 test/source/index.html
  4. +4 −0 test/test_generated_site.rb
View
@@ -54,6 +54,7 @@ def run
assign_pages!
assign_related_posts!
assign_highlighter_options!
assign_layout_data!
Jekyll.logger.debug "Pre-Render Hooks:", document.relative_path
document.trigger_hooks(:pre_render, payload)
@@ -233,6 +234,14 @@ def assign_highlighter_options!
payload["highlighter_suffix"] = converters.first.highlighter_suffix
end
private
def assign_layout_data!
layout = layouts[document.data["layout"]]
if layout
payload["layout"] = Utils.deep_merge_hashes(layout.data, payload["layout"] || {})
end
end
private
def permalink_ext
if document.permalink && !document.permalink.end_with?("/")
@@ -1,3 +1,6 @@
---
front_matter_var: variable from layout
---
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
View
@@ -5,6 +5,8 @@
h1. Welcome to my site
{{ layout.front_matter_var }}
h2. Please read our {{ site.posts | size }} Posts
<ul>
@@ -21,6 +21,10 @@ class TestGeneratedSite < JekyllUnitTest
assert @index.include?("#{@site.posts.size} Posts")
end
should "insert variable from layout into the index" do
assert @index.include?("variable from layout")
end
should "render latest post's content" do
assert @index.include?(@site.posts.last.content)
end

0 comments on commit 2cfcb23

Please sign in to comment.