Is it possible to convert a simple string ("Hello World!") to uppercase ("HELLO WORLD!")?
1 Answer
The upper filter is what you are looking for:
{% set var = 'Hello World' %} {# Print in UPPERCASE #} {{ var|upper }} {# 'HELLO WORLD' #} Besides upper there are also some other filters available to modify the capitalization style of your strings. Of course there is the lowercase equivalent lower and additionally there are some Craft exclusive filters available.
<ul> {# Set test strings #} {% set strLower = 'this is a test string' %} {% set strUpper = 'THIS IS A TEST STRING' %} {% set strMixed = 'this Is a TEST stRing' %} {# Apply Twig filters #} <li>upper: {{ strLower|upper }}</li> {# 'THIS IS A TEST STRING' #} <li>lower: {{ strUpper|lower }}</li> {# 'this is a test string' #} {# Apply filters provided by Craft #} <li>ucwords: {{ strLower|ucwords }}</li> {# 'This Is A Test String' #} <li>ucfirst: {{ strLower|ucfirst }}</li> {# 'This is a test string' #} <li>lcfirst: {{ strUpper|lcfirst }}</li> {# 'tHIS IS A TEST STRING' #} {# Combine filters for predictable application #} <li>ucwords: {{ strMixed|lower|ucwords }}</li> {# 'This Is A Test String' #} <li>ucfirst: {{ strMixed|lower|ucfirst }}</li> {# 'This is a test string' #} <li>lcfirst: {{ strMixed|upper|lcfirst }}</li> {# 'tHIS IS A TEST STRING' #} {# Examples for possible use cases #} <li>PascalCase: {{ strMixed|lower|ucwords|replace(' ', '') }}</li> {# 'ThisIsATestString' #} <li>camelCase: {{ strMixed|lower|ucwords|lcfirst|replace(' ', '') }}</li> {# 'thisIsATestString' #} </ul> - Sorry Victor, actually I wanted to make this edit only a proposal. Don't know why it applied directly!? SE is soooo new to me! You can revert this and I add an additional answer, if you want.carlcs– carlcs2014-06-14 13:52:57 +00:00Commented Jun 14, 2014 at 13:52
- Over 500reps SE allows you to edit directly, and why should somebody have something against it? ;)Victor– Victor2014-06-14 13:55:04 +00:00Commented Jun 14, 2014 at 13:55
- So there no way to just suggest changes if you have this "privilege"? Don't like that actually.carlcs– carlcs2014-06-14 13:57:18 +00:00Commented Jun 14, 2014 at 13:57
- I don't think so, but I'm also pretty new to this.Victor– Victor2014-06-14 13:58:39 +00:00Commented Jun 14, 2014 at 13:58
- 1@ChristianSeelbach No, there is no way. Also, you now can review the edits, suggested by "small" users. You earn this privilege at 500 reputation points in private betas, at 1,000 reputation points in public betas and at 2,000 reputation points in completely launched sites.nicael– nicael2014-06-14 14:23:02 +00:00Commented Jun 14, 2014 at 14:23