liquid

For loop, wrap every two posts in a div

北城以北 提交于 2019-11-27 10:09:59
问题 Basically, I am using Jekyll (which uses the Liquid templating language) and I am trying to write a for loop which wraps every two items in a div . This is my current loop: <div> {% for post in site.posts %} <a href="{{ post.url }}">{{ post.title }}</a> {% endfor %} </div> Which would output four posts like so: <div> <a href="#">Title</a> <a href="#">Title</a> <a href="#">Title</a> <a href="#">Title</a> </div> My desired output for four posts is: <div> <a href="#">Title</a> <a href="#">Title<

Liquid templates: even/odd items in for loop

允我心安 提交于 2019-11-27 09:44:36
问题 If I have a for loop in Liquid (using Jekyll), how can I target even (or odd) items only? I have tried: {% for item in site.posts %} {% if forloop.index % 2 == 1 %} but that doesn't seem to work. I have also tried: (forloop.index % 2) == 1 and: forloop.index - (forloop.index / 2 * 2) == 1 回答1: I think you'll want to use the cycle tag for this. For example: {% for post in site.categories.articles %} <article class="{% cycle 'odd', 'even' %}"></article> {% endfor %} If you want different HTML

Include jekyll / liquid template data in a YAML variable?

六眼飞鱼酱① 提交于 2019-11-27 06:58:15
I am using the YAML heading of a markdown file to add an excerpt variable to blog posts that I can use elsewhere. In one of these excerpts I refer to an earlier blog post via markdown link markup, and I use the liquid template data variable {{ site.url }} in place of the base URL of the site. So I have something like (trimmed it somewhat) --- title: "Decluttering ordination plots in vegan part 2: orditorp()" status: publish layout: post published: true tags: - tag1 - tag2 excerpt: In the [earlier post in this series]({{ site.url }}/2013/01/12/ decluttering-ordination-plots-in-vegan-part-1

Jekyll/Liquid Templating: How to group blog posts by year?

匆匆过客 提交于 2019-11-27 00:14:38
I'm rewriting my blog to use Jekyll. Jekyll uses the Liquid templating language so it makes it a little more difficult to learn how to customize. I'd like to group my list of blog posts by year. How would I write the Liquid code to be able to do this? {% for post in site.posts %} <li><!-- display post year here (but only once, per year) --></li> <li> <a href="{{ post.url }}">{{ post.title }}</a> </li> {% endfor %} If you want to break it down by year, here's the code: {% for post in site.posts %} {% capture this_year %}{{ post.date | date: "%Y" }}{% endcapture %} {% capture next_year %}{{ post

Sorted navigation menu with Jekyll and Liquid

旧时模样 提交于 2019-11-26 23:59:12
问题 I'm constructing a static site (no blog) with Jekyll/Liquid. I want it to have an auto-generated navigation menu that lists all existing pages and highlight the current page. The items should be added to the menu in a particular order. Therefore, I define a weight property in the pages' YAML: --- layout : default title : Some title weight : 5 --- The navigation menu is constructed as follows: <ul> {% for p in site.pages | sort:weight %} <li> <a {% if p.url == page.url %}class="active"{% endif

How does Jekyll date formatting work?

拜拜、爱过 提交于 2019-11-26 19:13:27
问题 I'm using Jekyll to generate a simple site. I want the date field to display in the format 12 September 2011 . I've found, through some creative googling, a bit of date-format manipulation, but nothing that seems to get me the month name. What I have is {{ page.date| date: "%m-%d-%Y" }} , which gets me output as 09-12-2011 , but isn't quite what I'm looking for. Is there any way to get the month as a name in Jekyll? Or, barring that, is there any documentation for the date attribute? 回答1:

Escaping double curly braces inside a markdown code block in Jekyll

瘦欲@ 提交于 2019-11-26 19:07:45
问题 I'm using Jekyll to create a documentation site wherein I am trying to document some code that contains handlebars-like syntax. For example {{foo}} . The problem is that Jekyll uses liquid tags and no matter what I do, my double curlies are getting ripped out by the liquid processor. By the way, I'm using kramdown as the markdown processor. Here is something I've tried: {% highlight html linenos %} Hello, my name is {{name}}. {% endhighlight %} This one removes the {{name}} section completely

How to escape liquid template tags?

断了今生、忘了曾经 提交于 2019-11-26 18:22:39
This sounds very easy, however I couldn't find it anywhere in the docs. How can I write {% this %} in a liquid template, without it being processed by the engine? Khaja Minhajuddin For future searchers, there is a way to escape without plugins, use the code below: {{ "{% this " }}%} and for tags, to escape {{ this }} use: {{ "{{ this " }}}} There is also a jekyll plugin for this which makes it a whole lot easier: https://gist.github.com/1020852 Raw tag for jekyll. Keeps liquid from parsing text betweeen {% raw %} and {% endraw %} Reference it is possible to disable liquid processing engine

An easy way to support tags in a jekyll blog

天大地大妈咪最大 提交于 2019-11-26 17:15:52
I am using the standard jekyll installation to maintain a blog, everything is going fine. Except I would really like to tag my posts. I can tag a post using the YAML front matter, but how do I generate pages for each tag that can will list all posts for a tag? Brian Clapper This gist will generate a page per category for you: https://gist.github.com/524748 It uses a Jekyll Generator plugin, plus a Page subclass. Christian Specht Here is a solution with alphabetically sorted tags on a single page . It uses Liquid only, which means that it works on GitHub Pages: {% capture tags %} {% for tag in

Include jekyll / liquid template data in a YAML variable?

一曲冷凌霜 提交于 2019-11-26 12:58:49
问题 I am using the YAML heading of a markdown file to add an excerpt variable to blog posts that I can use elsewhere. In one of these excerpts I refer to an earlier blog post via markdown link markup, and I use the liquid template data variable {{ site.url }} in place of the base URL of the site. So I have something like (trimmed it somewhat) --- title: \"Decluttering ordination plots in vegan part 2: orditorp()\" status: publish layout: post published: true tags: - tag1 - tag2 excerpt: In the