Forum Discussion
DavidO
2 years agoStrategist II
Has anyone got 'map' and 'join' to work on a liquid array? Code review please :)
Hi all I have been looking at options to capitalize the first letter of both names for users who have two first names saved in our database. For example: 'tony peter' becomes 'Tony Peter'. I ca...
- 2 years ago
DavidO map only works on properties and the property name should be where you have 'capitalize' in teh code. 'capitalize' is not a property of any item in your array, that's why this won't work.
Try this:
{% assign fullName = "tony peter" %} {% assign names = fullName | split: ' ' %} {%- capture capitalizedNames -%} {%- for name in names %}{{ name | capitalize }} {% endfor -%} {%- endcapture -%} {{ capitalizedNames }}
Arso
Practitioner III
DavidO map only works on properties and the property name should be where you have 'capitalize' in teh code. 'capitalize' is not a property of any item in your array, that's why this won't work.
Try this:
{% assign fullName = "tony peter" %}
{% assign names = fullName | split: ' ' %}
{%- capture capitalizedNames -%}
{%- for name in names %}{{ name | capitalize }} {% endfor -%}
{%- endcapture -%}
{{ capitalizedNames }}
Related Content
- 7 months ago