2016-04-20 25 views
1

我有一個哲基爾頁面,在這裏我有兩個文件夾:products_products/product_name使用頁面屬性包括聲明傑奇

,我有一個產品頁面MD文件含有本:

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

而這個簡單的佈局:

--- 
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> 
     <div class="half_right center"> 
     {% markdown _products/page.title/short.md %} 
     </div> 
     <div class="clear"></div> 

    </header> 
     {{content}} 
    </div> 
</div> 

然而在:{% markdown _products/page.title/short.md %}我似乎無法捕捉頁面標題,我該怎麼辦呢?

我的降價標籤:

# From: http://wolfslittlestore.be/2013/10/rendering-markdown-in-jekyll/ 
=begin 
    Jekyll tag to include Markdown text from _includes directory preprocessing with Liquid. 
    Usage: 
    {% markdown <filename> %} 
    Dependency: 
    - kramdown 
=end 
module Jekyll 
    class MarkdownTag < Liquid::Tag 
    def initialize(tag_name, text, tokens) 
     super 
     @text = text.strip 
    end 
    require "kramdown" 
    def render(context) 
     tmpl = File.read File.join Dir.pwd, "", @text 
     site = context.registers[:site] 
     tmpl = (Liquid::Template.parse tmpl).render site.site_payload 
     html = Kramdown::Document.new(tmpl).to_html 
    end 
    end 
end 
Liquid::Template.register_tag('markdown', Jekyll::MarkdownTag) 

誰能告訴我怎樣捕捉到{% markdown _products/page.title/short.md %}我得到這個錯誤的page.title:Liquid Exception: No such file or directory @ rb_sysopen - /home/tools/git/pagename.github.io/_products/page.title/short in _layouts/product.html

回答

1

我發現了一個不同的生成與溶液中的化身,這樣我就不需要一個插件了

讓我們假設你有降價文件john.md在路徑markdown_files我們可以然後我們可以做到以下幾點:

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

然後我們想要輸入的john.md文本現在john拍攝,我們可以把這個{{ john | markdownify }}

它不是一個圓滑的不是一個襯墊,但它的作品。根據您的設置,您可以使用include而不是include_relative

希望它可以幫助其他人,並感謝Jekyll IRC社區幫助我找到解決方案。