Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rustygeldmacher/jekyll-contentblocks
A Jekyll plugin giving you something like Rails' content_for
https://github.com/rustygeldmacher/jekyll-contentblocks
Last synced: about 1 month ago
JSON representation
A Jekyll plugin giving you something like Rails' content_for
- Host: GitHub
- URL: https://github.com/rustygeldmacher/jekyll-contentblocks
- Owner: rustygeldmacher
- License: mit
- Created: 2013-03-05T02:06:54.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2019-04-29T19:09:45.000Z (over 5 years ago)
- Last Synced: 2024-04-25T04:44:24.421Z (8 months ago)
- Language: Ruby
- Size: 43 KB
- Stars: 149
- Watchers: 7
- Forks: 13
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-jekyll-plugins - **Content Blocks** - contentblocks](https://rubygems.org/gems/jekyll-contentblocks)) by Rusty Geldmacher -- Lets you use Rails-like content_for tags in your templates, for passing content from your posts up to your layouts. (Tags)
README
# jekyll-contentblocks
CicleCI build: [![CircleCI](https://circleci.com/gh/rustygeldmacher/jekyll-contentblocks.svg?style=svg)](https://circleci.com/gh/rustygeldmacher/jekyll-contentblocks)
Gives you a mechanism in Jekyll to pass content up from pages into their parent
layouts. It's kind of like having Rails' content_for available for Jekyll.## Installation
jekyll-contentblocks supports Jekyll 2.3.0 and above. Any other version below
2.3.0 is not guaranteed to work.### Bundler (recommended)
Add this line to your Jekyll project's `Gemfile`:
```ruby
group :jekyll_plugins do
gem 'jekyll-contentblocks'
end
```Then execute:
```bash
$ bundle install
```### Standalone
Execute:
```bash
$ gem install jekyll-contentblocks
```And initialize it in a plugin:
```ruby
# _plugins/ext.rb
require "rubygems"
require "jekyll-contentblocks"
```## Usage
In your layout files, define `contentblock` blocks that say where content will
end up. For example, say the file `_layouts/default.html` looks like this:```html
{% contentblock scripts %}
{{ content }}
```
Now to add content to the sidebar from a post, you'd just need to do something like:
```html
---
layout: default
---Here is my post content.
{% contentfor sidebar %}
* Some content
* in a markdown list
* with some {{ 'liquid' }} tags too!
{% endcontentfor %}
```Note that we didn't add anything to the `scripts` block in the post. That's OK,
content blocks without any content will be ignored.### Skipping content conversion in a block
By default, a content block will be run through the converter for the current
file (Markdown, for instance). Sometimes this is not desirable, such as for
blocks containing code that shouldn't be modified. In the example above, content
in the `scripts` block will be converted by default. To prevent this, add the
`no-convert` option to the block, like this:```
{% contentblock scripts no-convert %}
```Now any content added to `scripts` will be placed in the block without any
formatting applied.### Checking if a block has content
We might want to check if the particular contentblock has content before using
it in our template. To do this, use the `ifhascontent` tag:```liquid
{% ifhascontent javascripts %}
{% contentblock javascripts %}
{% endifhascontent %}
```Similarly, there's the opposite tag, `ifnothascontent`:
```liquid
{% ifnothascontent sidebar %}
This is our default sidebar.
{% endifnothascontent %}
```## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request### Running the tests
Try to make sure that your changes work with all of the latest point releases
of Jekyll. To do this, run the test suite:```bash
> bundle
> bundle exec appraisal install
> bundle exec appraisal rpsec
```