Prevent Liquid from parsing of certain files in Jekyll - jekyll

I am using Jekyll + Liquid + Markdown to generate static html pages. Consequently, this is really a question specific to the Jekyll framework and Liquid template generator because there is syntax that conflicts with Liquid in some of my Markdown files.
Is there a quick and dirty work-around I can use for the time being in order to prevent Liquid from parsing certain files?

Use Raw:
Raw temporarily disables tag processing. This is useful for generating content (eg, Mustache, Handlebars) which uses conflicting syntax.
{% raw %}
In Handlebars, {{ this }} will be HTML-escaped, but
{{{ that }}} will not.
{% endraw %}

Related

How can I render HTML using Liquid in asciidoc in Jekyll?

In my current Jekyll setup I am writing all my posts using the asciidoc (.adoc) file format, specifically I'm using these plugins
plugins:
- jekyll-asciidoc
- jekyll-redirect-from
- jekyll-feed
I am in need to create a custom HTML component which I have added in component.html under the _includes folder, following the includes feature of Jekyll.
I am able at the moment to use Liquid in a Markdown file to render the HTML component by just using
{% include component.html %}
at any point in my posts, but I can't do the same with asciidoc files. I've taken a look at their documentation and I can't find a suitable way to make use of this Jekyll feature.
Is there a way to use Liquid in asciidoc?
After a little bit of research I've found a couple of things with which I was able to inject _includes HTML components in an asciidoc file.
jekyll-asciidoc has a special page attribute to enable Liquid preprocessing, you can find the docs at :page-liquid:
So, in order to enable Liquid preprocessing you just have to add this to the asciidoc post
:page-liquid:
With this, Jekyll is going to parse every Liquid statement in your file before actually passing it to the asciidoc generator.
The post needs another little change at this point, citing the docs:
If you’re using the Liquid include tag to include HTML into the AsciiDoc document, enclose it in a passthrough block.
++++
{% include file.html %}
++++
By default :page-liquid: will escape Liquid generated content, which is why you need to enclose the {% include ... %} statement in the asciidoc Passthrough construct ++++ that is going to inject raw HTML into the page itself.
In conclusion, this is what an example post should look like:
_includes/component.html
<p>Some sample text</p>
_posts/liquid-in-asciidoc.adoc
---
title: "HTML component in adoc
---
:page-liquid:
++++
{% include component.html %}
++++

Can an external template loaded with the 'include' keyword contain Jinja syntax?

I just learned about Jinja's include function and wondered if it can also evaluate Jinja syntax within the loaded template?
So what I mean is something like:
view1.html
{% block content %}
{% include "subview1.html" %}
{% endblock %}
subview1.html
{% for image in images %}
....
{% endfor %}
The include documentation states:
Included templates have access to the variables of the active context by default.
And reading the Import Context Behavior information, I learned that
By default, included templates are passed the current context, and imported templates are not.
So I conclude that the loaded templates can refer to the context of the main HTML. But it's not clear to me if they can also contain Jinja logic. Although I suspect it won't work since the templates are rendered first and then included.
The include tag is useful to include a template and return the rendered contents of that file into the current namespace

Adding a variable in a Liquid template for multilingual?

I have a Jekyll project and I'm trying to implement multilingual functionality.
My data files were stored in _data/my_data.yml, and accessed in the templates via the {% for data in site.data.my_data %} Liquid template tag.
I have now copied and translated my data files into _data/en/my_data.yml and _data/it/my_data.yml and created two .md files, using the same template, with respective lang attributes in the front matter.
I am trying to dynamically access the correct data based on this lang attribute however it's throwing all sorts of errors.
Things I've tried
{% for data in site.data.[page.lang].my_data %}
{% for data in site.data[page.lang]my_data %}
{% for data in site.data.{{page.lang}}.my_data %}
Any ideas?
In case anyone runs into this in the future, solved it with pretty much the only combination I hadn't tried yet:
{% for data in site.data[page.lang].my_data %}

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.
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

Embedding Markdown in blockquote plugin in Octopress

I like the functionality of the blockquote plugin for Octopress (http://octopress.org/docs/blogging/plugins/). It would give me a nice way of attributing the quote to the author.
However, I could not figure out how to blockquote content that is in markdown.
Here is an example of what I tried:
{% blockquote Author http://sourceurl.com %}
[Octopress](http://octopress.org/) is a blogging framework written by [Brandon Mathis](http://brandonmathis.com/)
([#imathis](https://twitter.com/#!/imathis)) which sits on top of [Jekyll](https://github.com/mojombo/jekyll). Jekyll is
a static site generator, meaning there's no database associated with your blog. Instead of writing everything in a
{% endblockquote %}
Any advice? It seems something like this might work: Embedding Markdown in Jekyll HTML
I've got this on a github octopress deploy right here: http://www.railsonmaui.com and you can find the source to this article here: https://github.com/justin808/justin808.github.io/blob/source/source/_posts/2013-04-27-octopress-setup-with-github-and-org-mode.markdown
(Octopress freely deployed on github is seriously cool, especially with org-mode)
Try using the {% raw %} ... {% endraw %} tags. This will prevent the enclosed content from being parsed.