Skip to content

Instantly share code, notes, and snippets.

@bdesham
Last active August 29, 2015 14:16
Show Gist options
  • Save bdesham/ea83c931ef6bf35c8f65 to your computer and use it in GitHub Desktop.
Save bdesham/ea83c931ef6bf35c8f65 to your computer and use it in GitHub Desktop.
A minimal Jekyll site showing a behavior I can’t explain
title date layout
Test post
2015-03-10 11:32:13 -0400
standard

This is one paragraph.

{% myblock %} This paragraph is in a custom block. {% endmyblock %}

Third paragraph!

---
layout: null
---
<!DOCTYPE html>
<html lang="en">
<body>
{% for post in site.posts %}
<h2>{{ post.title }}</h2>
<p>The block is "{{ post.my_block_contents }}"</p>
{% endfor %}
</body>
</html>
class MyBlock < Liquid::Block
def render(context)
# Get the current post's post object
id = context['page']['id']
posts = context.registers[:site].posts
post = posts[posts.index {|post| post.id == id}]
contents = super
post.data['my_block_contents'] = contents
contents
end
end
Liquid::Template.register_tag('myblock', MyBlock)
<!DOCTYPE html>
<html lang="en">
<body>
{{ content }}
<hr/>
{% if page.my_block_contents %}
{{ page.my_block_contents }}
{% else %}
no block contents
{% endif %}
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment