How to list pages with custom layouts in Jekyll

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 YYYY-MM-DD-post-name.md, if a markdown file is formatted as name-of-page.md 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 %}
Code language: PHP (php)

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 slight change in the code will list only those pages that use custom-page as layout.