Capitalizing every word in the Custom field | Community
Skip to main content

Capitalizing every word in the Custom field

  • July 10, 2022
  • 1 reply
  • 0 views

Denis17

Hello there,

I faced an issue trying to capitalize every word in the custom field.

I found this part of the code on other resources that utilizes liquid markup for such purposes:

{% assign words = ticket.ticket_field_6399604137869 | split: "_" %}{% capture titlecase %}{% for word in words %}{{ word | capitalize }}{% endfor %}{% endcapture %}{{ titlecase }}

It works almost perfectly capitalizing every word, but it doesn't split the words no matter what I do.

For Example instead of Oregon Lottery, I receive OregonLottery once the macro is applied. (The tag is oregon_lottery)

I tried filter (join: " ") in the multiple places within the code block, but it didn't help.

Could someone help with this task? Maybe there is an alternative code that can be used?

I would appreciate any help!

1 reply

Rafael20
  • July 11, 2022

You could use the following:

{% assign words = ticket.ticket_field_6399604137869 | split: '_' %}{% capture titlecase %}{% for word in words %}{{word | capitalize}} {% endfor %}{% endcapture %}
{{titlecase | remove_last: ' '}}

Adding a white space to each capitalized word in the for loop, while removing the last one when applied.