8000 Add top-level `layout` liquid variable to Documents by ayastreb · Pull Request #6073 · jekyll/jekyll · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add top-level layout liquid variable to Documents #6073

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

Merged
merged 1 commit into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/jekyll/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def run
assign_pages!
assign_related_posts!
assign_highlighter_options!
assign_layout_data!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if a plugin modifies the layout data?


Jekyll.logger.debug "Pre-Render Hooks:", document.relative_path
document.trigger_hooks(:pre_render, payload)
Expand Down Expand Up @@ -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"]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you do if that layout has layouts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?("/")
Expand Down
3 changes: 3 additions & 0 deletions test/source/_layouts/default.html
Original file line number Diff line number Diff line change
@@ -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">

Expand Down
2 changes: 2 additions & 0 deletions test/source/index.html
AC22
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

h1. Welcome to my site

{{ layout.front_matter_var }}

h2. Please read our {{ site.posts | size }} Posts

<ul>
Expand Down
4 changes: 4 additions & 0 deletions test/test_generated_site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
0