【发布时间】:2013-10-29 03:15:38
【问题描述】:
我想将我帖子的打印类别名称转换为标题大小写。我找不到合适的液体过滤器。我尝试使用破折号和驼峰过滤器,但没有骰子。
或者,我想打印在 YAML frontmatter 中写入的类别名称。
例如,对于具有以下内容的帖子:
category: Here's the Category
当我提到名字时:
{% for cat in site.categories %}
<h1>{{ cat[0] }}</h1>
{% endfor %}
我在页面上看到“这里是类别”。我想看到“Here's the Category”甚至“Here's The Category”,我可以替换(替换:'The'、'the')我想要小写的几篇文章。
编辑
对于像我这样绝望的人来说,这个令人作呕的 hack 有效,其中 n 是您在类别标题中拥有的最大单词数。
{% for cat in site.categories %}
{% assign words = cat[0] | split: ' ' %}
<h1>{{ words[0] | capitalize | replace:'The','the'}} {{ words[1] | capitalize }} {{ words[2] }} {{ words[3] | capitalize }} {{ words[4] | capitalize }} {{ words[n] | capitalize }}</h1>
{% endfor %}
如果有人知道更优雅的方法,我将不回答这个问题。
【问题讨论】: