如何在 Liquid/Jekyll 中将包含引号的字符串作为“include”参数传递?

Rob*_*bin 5 yaml liquid jekyll

考虑:我想将一段文本作为include标签中的参数传递。文本块包含引号。例如:

Breaking news:

Area man says, "This is newsworthy!"
Run Code Online (Sandbox Code Playgroud)

我可以想到几种方法来做到这一点:

1. 用单引号括起来

{%
    include newsitem.html
    content='Breaking news:

Area man says, "This is newsworthy!"'
%}
Run Code Online (Sandbox Code Playgroud)

这并不理想,因为文本块中可能有单引号/撇号。

2. 使用captures

{% capture newscontent %}
Breaking news:

Area man says, "This is newsworthy!"
{% endcapture %}
{%
    include newsitem.html
    content=newscontent
%}
Run Code Online (Sandbox Code Playgroud)

这并不理想,因为它很冗长。

3.转义引号

{%
    include newsitem.html
    content="Breaking news:

Area man says, \"This is newsworthy!\""
%}
Run Code Online (Sandbox Code Playgroud)

这并不理想,因为如果有很多引号,那么它们都需要反斜杠,添加起来会很麻烦。

4. 使用capturesinclude

{% capture content %}{% include_relative newscontent.md %}{% endcapture %}
{%
    include newsitem.html
    content=content
%}
Run Code Online (Sandbox Code Playgroud)

这并不是很理想,因为它也相当冗长。

5. 使用 frontmatter 和/或 YAML

---
newscontent: |
  Breaking news:

  Area man says, "This is newsworthy!"
---

{%
    include newsitem.html
    content=page.newscontent
%}
Run Code Online (Sandbox Code Playgroud)

这并不理想,因为它以一种奇怪的方式分散页面内容。


现在,我绝对承认这些都是非常微不足道的抱怨。但主要是为了更好地熟悉 Jekyll/liquid,我想知道是否有另一种方法可以将包含引号的多行参数传递给include. 如果我可以使用反引号或文本内容中不常见的其他字符,那就太好了:

{%
    include newsitem.html
    content=`Breaking news:

Area man says, "This is newsworthy!"`
%}
Run Code Online (Sandbox Code Playgroud)

不幸的是,这似乎不受支持。你怎么看?谢谢!