Something is missing for you. Adding values ββto data works great for both pages and posts.
See my repository for reference.
Here I add the attribute "foo" to all pages and posts
_plugins / foo.rb
module Foo class Generator < Jekyll::Generator def generate(site) puts "Our plugin is running" puts site.pages.inspect puts site.posts.inspect site.pages.each do |page| page.data['foo'] = 'bar' end site.posts.each do |post| post.data['foo'] = 'bar' end end end end
Here I add "foo" to the mailing list layout:
post.html
<article class="post-content"> {{ content }} {{ page.foo }} </article>
And page layout :
page.html
<article class="post-content"> {{ content }} {{ page.foo }} </article>
After running jekyll b I can see the output in post and the page where I expect them.
In a separate branch, I re-created your setting, where you iterate over all pages and posts:
default.html ( source )
{% for post in site.posts %} <div class="postbaz">{{ post.foo }}</div> {% endfor %} {% for page in site.pages %} <div class="pagebaz">{{ page.foo }}</div> {% endfor %}
_plugins / foo.rb ( source )
site.pages.each do |page| page.data['foo'] = 'bar' end site.posts.each do |post| post.data['foo'] = 'baz' end
(Note that the bar property is for the page and baz is for the message.)
It displays as expected:
site / index.html ( source )
<div class="postbaz">baz</div> <div class="pagebaz">bar</div> <div class="pagebaz">bar</div> <div class="pagebaz">bar</div> <div class="pagebaz">bar</div>
source share