New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add top-level `layout` liquid variable to Documents #6073

Merged
merged 1 commit into from Jun 14, 2017
Jump to file or symbol
Failed to load files and symbols.
+18 −0
Diff settings

Always

Just for now

View
@@ -54,6 +54,7 @@ def run
assign_pages!
assign_related_posts!
assign_highlighter_options!
assign_layout_data!

This comment has been minimized.

@parkr

parkr May 12, 2017

Member

What if a plugin modifies the layout data?

@parkr

parkr May 12, 2017

Member

What if a plugin modifies the 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"]]

This comment has been minimized.

@parkr

parkr May 12, 2017

Member

What do you do if that layout has layouts?

@parkr

parkr May 12, 2017

Member

What do you do if that layout has layouts?

This comment has been minimized.

@ayastreb

ayastreb May 13, 2017

Contributor

Not sure... basically the problem is that we don't have layout data in payload when we render document here. I've tried to move the place_in_layouts call before rendering the document (because we add layout data to payload in that method), but that breaks a lot of tests.

Not sure how to fix this without too much changes :)

@ayastreb

ayastreb May 13, 2017

Contributor

Not sure... basically the problem is that we don't have layout data in payload when we render document here. I've tried to move the place_in_layouts call before rendering the document (because we add layout data to payload in that method), but that breaks a lot of tests.

Not sure how to fix this without too much changes :)

This comment has been minimized.

@parkr

parkr May 12, 2017

Member

What if the document doesn't have a layout parameter? layouts[nil]?

@parkr

parkr May 12, 2017

Member

What if the document doesn't have a layout parameter? layouts[nil]?

This comment has been minimized.

@ayastreb
@ayastreb
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
ProTip! Use n and p to navigate between commits in a pull request.