在 include 语句 jekyll 中使用 page 属性
Use page attribute in include statement jekyll
我有一个 jekyll 页面,其中有两个文件夹: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
我发现了一个与 jekyll 不同的内置解决方案,这样我就不需要插件了
假设您在路径 markdown_files
中有降价文件 john.md
我们可以然后我们可以执行以下操作:
{% capture john %}
{% include_relative markdown_files/john.md %}
{% endcapture %}
然后我们要输入现在在 john
中捕获的 john.md
的文本,我们可以把这个 {{ john | markdownify }}
它不是圆滑的,也不是单一的衬里,但它确实有效。根据您的设置,您可以使用 include
而不是 include_relative
希望它可以帮助其他人,并感谢 Jekyll IRC 社区帮助我找到解决方案。
我有一个 jekyll 页面,其中有两个文件夹: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
我发现了一个与 jekyll 不同的内置解决方案,这样我就不需要插件了
假设您在路径 markdown_files
中有降价文件 john.md
我们可以然后我们可以执行以下操作:
{% capture john %}
{% include_relative markdown_files/john.md %}
{% endcapture %}
然后我们要输入现在在 john
中捕获的 john.md
的文本,我们可以把这个 {{ john | markdownify }}
它不是圆滑的,也不是单一的衬里,但它确实有效。根据您的设置,您可以使用 include
而不是 include_relative
希望它可以帮助其他人,并感谢 Jekyll IRC 社区帮助我找到解决方案。