How to list pages with custom layouts in Jekyll

Nov 19, 2014
Jekyll is a blog aware static website generator that is written in Ruby and uses Liquid for templating and Markdown to write posts and pages, Jekyll also offers build in support for SASS, SCSS, LESS and CoffeeScript.

Jekyll follows a naming conversion to differ a post or page. Jekyll knows a specific markdown file is a post when the file is formatted in, if a markdown file is formatted as Jekyll knows it’s a page. You can always use a layout: string in the front-matter to select choose a specific layout or template file to be used while parsing and building a Jekyll based Website.

{% for page in site.pages %} 
{% if page.layout == "custom-page" %} <a href="{{page.url}}">{{page.title}}</a> 
{% endif %} 
{% endfor %}

That is one way to list posts in Liquid. If you want to list a specific layout based page that follows the page naming convention but does not use the layout: as page, we can fix this issue by tweaking the code a bit by adding a if statement to it. We will be using the layout custom-page to separate the stock or default page layout. This small change in the code will list only those pages that use custom-page as layout.

If you like this content, please consider buying me a coffee.

Buy me a coffeeBuy me a coffee

You will get access to contributer exclusive resources and content.

Thank you!

Darryl Dias

I am a student, artist, and author currently living in Florida. My interests range from technology to arts. I am also interested in programming, writing

Analytics by GoSquared