Steve
Steve

Reputation: 1631

Is it possible in gh-pages Jekyll to have {{content}} expand without evaluating liquid tags?

I'm trying to use GitHub Pages for my project's documentation, but it includes generated html files that turn out to have illegal liquid tags. I don't need any expansion beyond the _layout itself, but as far as I can tell, any {% ... %} tags in the articles' content themselves are also evaluated and there seems to be no way to suppress this, other than adding {% raw %}...{% endraw %} around the entire contents of every single article.

Is there any way to do this at the call site? Something along the lines of {{ content | unrendered }} would be excellent.

Note: this seems to be the opposite problem to many others, who are using page.content in a pre-render context and wanting it to be rendered; I've tried page.content but as far as I can tell it's exactly the same in my case, so no dice.

Upvotes: 0

Views: 172

Answers (1)

David Jacquel
David Jacquel

Reputation: 52809

page.content was raw in the jekyll 2.x era. Now its rendered content.

You can use a hook plugin to add a page.raw field on any page.

Jekyll::Hooks.register :pages, :pre_render do |document|
  document.data['raw'] = document.content
end

If you want to do the same on posts and collections items, use a documents hook :

Jekyll::Hooks.register :documents, :pre_render do |document|

Note :

  • In :pre_render hooks document.content contains raw content
  • In :post_render hooks document.content contains rendered content

Upvotes: 1

Related Questions