Giter VIP home page Giter VIP logo

include-tag's Introduction

Octopress Include Tag

This replaces Jekyll's include tag and adds support for conditional rendering, in-line filters and including partials from Octopress Ink plugins.

Build Status Gem Version License

Installation

If you're using bundler add this gem to your site's Gemfile in the :jekyll_plugins group:

group :jekyll_plugins do
  gem 'octopress-include-tag'
end

Then install the gem with Bundler

$ bundle

To install manually without bundler:

$ gem install octopress-include-tag

Then add the gem to your Jekyll configuration.

gems:
  -octopress-include-tag

Usage

Use this just like the regular Jekyll include tag.

{% include foo.html %}                // renders _includes/foo.html
{% include foo.html happy="yep"  %}   // samea as above but {{ include.happy }} == "yep"

Include partials stored as a variable.

{% assign post_sidebar = "post_sidebar.html" %}
{% include post_sidebar %}   // renders _includes/post_sidebar.html

Include partials conditionally, using if, unless and ternary logic.

{% include sidebar.html if site.theme.sidebar %}
{% include comments.html unless page.comments == false %}
{% include (post ? post_sidebar : page_sidebar) %}

Filter included partials.

{% include foo.html %}           //=> Yo, what's up
{% include foo.html | upcase %}  //=> YO, WHAT'S UP

Yes, it can handle a complex combination of features… but can you?

{% include (post ? post_sidebar : page_sidebar) | smart_quotes unless site.theme.sidebar == false %}

Include partials with an Octopress Ink plugin.

It's easy to include a partial from an Ink theme or plugin.

Here's the syntax

{% include [plugin-slug]:[partial-name] %}

Some examples:

{% include theme:sidebar.html %}   // Include the sidebar from a theme plugin
{% include twitter:feed.html %}    // Include the feed from a twitter plugin

Overriding theme/plugin partials

Plugins and themes use this tag internally too. For example, the octopress-feeds plugin uses the include tag to render partials for the RSS feed.

{% for post in site.articles %}
  <entry>
    {% include feeds:entry.xml %}
  </entry>
{% endfor %}

If you want to make a change to the entry.xml partial, you could create your own version at _plugins/feeds/includes/entry.xml. Now whenever {% include feeds:entry.xml %} is called, the include tag will use your local partial instead of the plugin's partial.

Note: To make overriding partials easier, you can copy all of a plugin's partials to your local override path with the Octopress Ink command:

$ octopress ink copy [plugin-slug] [options]

To copy all includes from the feeds plugin, you'd run:

$ octopress ink copy feeds --includes

This will copy all of the partials from octopress-feeds to _plugins/feeds/includes/. Modify any of the partials, and delete those that you want to be read from the plugin.

To list all partials from a plugin, run:

$ octopress ink list [plugin-slug] --includes

Note: When a plugin is updated, your local partials may be out of date, but will still override the plugin's partials. Be sure to watch changelogs and try to keep your modifications current.

Contributing

  1. Fork it ( https://github.com/octopress/include-tag/fork )
  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 a new Pull Request

include-tag's People

Contributors

imathis avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.