Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get url of page in Liquid (Jekyll)

I am writing documentation with Github pages (Jekyll) and in one page I want to make link to another. I tried to use {% page_url post-name %} but with no luck. When I run bundle exec jekyll serve I get this exception:

Liquid Exception: no implicit conversion of nil into String in docs/page1.md

My posts are in subdirectory docs and the structure of my documentation looks like this:

CNAME
_config.yml
_includes/
_layouts/
_site/
css/
docs/
   page1.md
   page2.md
   page3.md
imgs/
js/
index.md

The configuration file contains:

safe: true
lsi: false
pygments: true
markdown: kramdown

All pages in docs/ subdirectory contains YAML block:

---
layout: docs
title: Page Two
permalink: /docs/page2/
---

And now, I try to get page url of this page2:

{% page_url page2 %}
{% page_url docs/page2 %}
{% page_url /docs/page2/ %}
{% page_url /docs/page2.md/ %}

None of this works, I am still getting Liquid Exception.

So what is the proper way to get url of page in subdirectory?

like image 636
vasco Avatar asked Nov 25 '13 17:11

vasco


2 Answers

use the generic link tag: {% link _collection/name-of-document.md %}

so, something like {% link docs/page2.md %}

like image 121
Alicia Avatar answered Sep 21 '22 02:09

Alicia


You should be using the `{% post_url %}' tag, eg:

{% post_url 2010-07-21-name-of-post %}

More details in Jekyll's docs: http://jekyllrb.com/docs/templates/#post-url

like image 32
Seth Warburton Avatar answered Sep 18 '22 02:09

Seth Warburton