diff --git a/features/layout_data.feature b/features/layout_data.feature index 78998665..c2af5b70 100644 --- a/features/layout_data.feature +++ b/features/layout_data.feature @@ -35,3 +35,36 @@ Feature: Layout data When I run jekyll build Then the "_site/index.html" file should exist And I should see "page content\n foo: my custom data" in "_site/index.html" + + Scenario: Inherit custom layout data and clear when not present + Given I have a _layouts directory + And I have a "_layouts/default.html" file with content: + """ + --- + bar: i'm default + --- + {{ content }} foo: '{{ layout.foo }}' bar: '{{ layout.bar }}' + """ + And I have a "_layouts/special.html" file with content: + """ + --- + layout: default + foo: my special data + bar: im special + --- + {{ content }} + """ + And I have a "_layouts/page.html" file with content: + """ + --- + layout: default + bar: im page + --- + {{ content }} + """ + And I have an "index.html" page with layout "special" that contains "page content" + And I have an "jekyll.html" page with layout "page" that contains "page content" + When I run jekyll build + Then the "_site/index.html" file should exist + And I should see "page content\n foo: 'my special data' bar: 'im special'" in "_site/index.html" + And I should see "page content\n foo: '' bar: 'im page'" in "_site/jekyll.html" diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index a473b183..a5d35607 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -209,10 +209,13 @@ module Jekyll used = Set.new([layout]) + # Reset the payload layout data to ensure it starts fresh for each page. + payload["layout"] = nil + while layout Jekyll.logger.debug "Rendering Layout:", path payload["content"] = output - payload["layout"] = Utils.deep_merge_hashes(payload["layout"] || {}, layout.data) + payload["layout"] = Utils.deep_merge_hashes(layout.data, payload["layout"] || {}) self.output = render_liquid(layout.content, payload, diff --git a/lib/jekyll/renderer.rb b/lib/jekyll/renderer.rb index f116cf60..f9eb94be 100644 --- a/lib/jekyll/renderer.rb +++ b/lib/jekyll/renderer.rb @@ -136,10 +136,13 @@ module Jekyll used = Set.new([layout]) + # Reset the payload layout data to ensure it starts fresh for each page. + payload["layout"] = nil + while layout payload['content'] = output payload['page'] = document.to_liquid - payload['layout'] = Utils.deep_merge_hashes(payload['layout'] || {}, layout.data) + payload['layout'] = Utils.deep_merge_hashes(layout.data, payload["layout"] || {}) output = render_liquid( layout.content,