Capitalize first letter of each word with liquid syntax?
There is a way to achieve this using only Liquid syntax. No need for any plugins.
Break down your string of words into an array and use a for loop combined with the capitalize filter to capitalize the first letter of each word. If you appropriately encapsulate this inside a capture statement you are left with the first character in every word capitalized.
{% assign words = "Hi, how are you today?" | split: ' ' %}
{% capture titlecase %}
{% for word in words %}
{{ word | capitalize }}
{% endfor %}{% endcapture %}
{{ titlecase }}
Output:
Hi, How Are You Today?
Notice that all of this is on a single line and there is only one occurrence of whitespace within the entire capture statement!
I would suggest to use a plugin to obtain this behavior
_plugins/_capitalize_all.rb
:
require 'liquid'
require 'uri'
# Capitalize all words of the input
module Jekyll
module CapitalizeAll
def capitalize_all(words)
return words.split(' ').map(&:capitalize).join(' ')
end
end
end
Liquid::Template.register_filter(Jekyll::CapitalizeAll)
Usage:
{{ "mein text" | capitalize_all }}
how about setting this up with CSS ?
title {
text-transform:capitalize;
}
edit: i did a typo about text-transform, now it is fixed;