Any way to Titlecase a string in a blueprint?

I currently have a structure that allows for my client to choose the programming languages they can then assign to a project—Those structure items are then fed into a select that uses them as a query:

        label: Coding Language
        type: select
        options: query
          fetch: page.parent.langOptions.toStructure 
          text: "{{ structureItem.category }}"
          value: "{{ structureItem.category.slug }}"

I now want the language to show on the parent page as a small bit of info with the subpage title:

info: "{{ }} | {{ page.category }} | {{ page.language }}" 

The issue is because I used the slug as a value instead of the text itself, it’s showing as lowercase. Is there any way to title case the string while keeping the value a slug? I’m currently keeping the value a slug because the website will also need to be able to filter by different types of projects in the future and that feels easiest to do with a slug.


All field methods: Field methods | Kirby CMS

Oops, sorry, that is all uppercase.

For Titlecase, there is no field method, so you would have to create one:

I’ve followed the field method page like so:

  • I’ve made a folder called plugins(I was starting from the simple theme not starterkit)
  • Made a folder inside that called title-case
  • Made an index.php with the following:
Kirby::plugin('kcaden20/titlecase', [
    'fieldMethods' => [
        'titlecase' => function ($field) {
            return ucfirst($field->value) ;

Ok I got it working! I just forgot the alias that needs to be added!

1 Like