我想将我的帖子的打印类别名称转换为标题大小写。我找不到合适的液体过滤器。我尝试使用破折号和驼峰过滤器,但没有骰子。
或者,我想打印 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”)我想要小写的几篇文章。
EDIT
对于像我这样绝望的人来说,这个令人厌恶的黑客是有效的,其中 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 %}
如果有人知道更优雅的方法,我将不回答这个问题。
您可以通过使用来实现您想要的部分capitalize
filter:
Input
{{ 'capitalize me' | capitalize }}
Output
Capitalize me
Source http://docs.shopify.com/themes/liquid-basics/output#manipulation.
另一种可能性是使用join
and camelize
:
{{ "here's the category" | join: '-' | camelize }}
它应该打印“Here's The Category”,但camelize可能有问题here's
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)