Skip to content
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 PageDrop to provide Liquid templates with data #7992

Merged
merged 7 commits into from Mar 26, 2020
35 changes: 35 additions & 0 deletions docs/_docs/pages.md
Expand Up @@ -34,3 +34,38 @@ If you have a lot of pages, you can organize them into subfolders. The same subf
## Changing the output URL

You might want to have a particular folder structure for your source files that changes for the built site. With [permalinks](/docs/permalinks) you have full control of the output URL.

## Liquid Representation

From Jekyll 4.1 onwards, there is a minor change in how instances of `Jekyll::Page` are exposed to layouts and other Liquid
templates. `Jekyll::Page` instances now use a `Liquid::Drop` instead of a `Hash`. This change results in greater performance
for a site with numerous *standlone pages not within a collection*.

### For plugin developers

While end-users need not take any extra action due to this change, plugin authors depending on the existing behavior *may* need
ashmaroli marked this conversation as resolved.
Show resolved Hide resolved
to make minor changes to their plugins.

If a `Jekyll::Page` subclass' `to_liquid` method calls `super`, it will have to be slightly modified.
```ruby
class Foo::BarPage < Jekyll::Page
def to_liquid(*)
payload = super # This needs to be changed to `super.to_h`
# to obtain a Hash as in v4.0.0.

do_something(payload) # Logic specific to `Foo::BarPage` objects
end
end
```

`Jekyll::Page` subclasses won't inherit the optimization automatically until the next major version. However, plugin authors
can opt-in to the optimization in their subclasses by wrapping the temporary `liquid_drop` method if the subclass doesn't
override the superclass method:
```ruby
class Foo::BarPage < Jekyll::Page
def to_liquid(*)
liquid_drop # Returns an instance of `Jekyll::Drops::PageDrop`.
# Will be removed in Jekyll 5.0.
end
end
```