craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 635 forks source link

Add camelcase template filters #972

Closed angrybrad closed 7 years ago

angrybrad commented 7 years ago

Created by: Jason McCallister (themccallister@gmail.com) on 2015/03/20 17:34:31 +0000 Votes at time of UserVoice import: 7


Craft comes with its own set of Twig filters that are listed here:

http://buildwithcraft.com/docs/templating/filters

It would be nice, since everything in Craft is camel cased, for Craft to add a custom camelcase filter.

The only real solution right now is to do something like this:

{{ variable | title | replace(' ', '') | lcfirst }}

Which is using a custom Craft Twig filter (lcfirst).

angrybrad commented 7 years ago

Posted by Jason McCallister (themccallister@gmail.com) on 2015/03/20 17:34:31 +0000

Thanks Brandon!

angrybrad commented 7 years ago

Posted by Brandon Kelly (brandon@pixelandtonic.com) on 2015/03/06 03:54:45 +0000

Just edited the idea to remove the 'slugify' half of the request. FFR please keep each idea limited to one FR.

angrybrad commented 7 years ago

Posted by Lindsey DiLoreto (lindsey@doublesecretagency.com) on 2015/03/11 04:48:18 +0000

This is half-done... As of Craft 2.4, there is now a "kebab" filter (basically a slug filter):

http://buildwithcraft.com/docs/templating/filters#kebab

{{ myVar | kebab }}

angrybrad commented 7 years ago

Posted by Lindsey DiLoreto (lindsey@doublesecretagency.com) on 2015/03/11 04:48:18 +0000

Sounds awesome, this would be great!

{{ myVar | slug }}

{{ myVar | camelCase }}

angrybrad commented 7 years ago

Craft 2.5 added a ‘camel’ Twig filter (as well as ‘pascal’ and ‘snake’).