Lars Nielsen Lars Nielsen - 5 months ago 10
Ruby Question

Use page attribute in include statement jekyll

I have a jekyll page where I have the the two folders:


and I have a product page md file containg this:

title: product_title
subtitle: subtilte
layout: product
description: long description
product_icon: product_image_path

And this simple layout:

layout: default
<!-- Main -->
<div id="main">
<div id="content" class="container">
<header id="product_header">
<div class="half_left center">
<img id="product_icon" src="/assets/{{ page.product_icon }}" alt="">
<h2 id="product_title">{{ page.title }}</h2>
<h3 id="product_subtitle">{{page.subtitle}}</h3>
<div class="half_right center">
{% markdown _products/page.title/ %}
<div class="clear"></div>


However in:
{% markdown _products/page.title/ %}
I seem unable to capture the page title, how can I do this?

My markdown tag:

# From:
Jekyll tag to include Markdown text from _includes directory preprocessing with Liquid.
{% markdown <filename> %}
- kramdown
module Jekyll
class MarkdownTag < Liquid::Tag
def initialize(tag_name, text, tokens)
@text = text.strip
require "kramdown"
def render(context)
tmpl = File.join Dir.pwd, "", @text
site = context.registers[:site]
tmpl = (Liquid::Template.parse tmpl).render site.site_payload
html =
Liquid::Template.register_tag('markdown', Jekyll::MarkdownTag)

Can someone tell me how I capture the page.title in the
{% markdown _products/page.title/ %}
I get this error:
Liquid Exception: No such file or directory @ rb_sysopen - /home/tools/git/ in _layouts/product.html


I found a different a build in solution with jekyll, such that I did not neeed a plugin in

let us say you have markdown file in path markdown_files we can then we can do the following:

{% capture john %}
    {% include_relative markdown_files/ %}
{% endcapture %}

Then where we want to input the text of now captured in john we can put this {{ john | markdownify }}

It is not a sleek an not a one liner, but it works. Depending on your setup you can use include instead of include_relative

Hope it can help someone else, and thank to the Jekyll IRC community for helping me find a solution.