최근 검색


최근 검색 없음

Capitalise names with apostrophes

답변함


2022년 8월 16일에 게시됨

How can we use liquid JS to change bob o’dwyer to Bob O’Dwyer Note first letter plus after apostrophe is capital

0

1

댓글 1개

Hey Sal. Here's one way to can accomplish that (whitespace added for clarity):

{% assign names = ticket.requester.name | split: ' ' %}
{% for name in names %}
    {% if name contains "'" %}
        {% assign split_name = name | split: "'" %}
        {% for part in split_name %}
            {{part | capitalize}}{% unless forloop.last %}'{% endunless %}
        {% endfor %}
    {% else %}
        {{name | capitalize}}
    {% endif %}
    {% unless forloop.last %}{{' '}}{% endunless %}
{% endfor %}

Here it is without spaces:

{% assign names = ticket.requester.name | split: ' ' %}{% for name in names %}{% if name contains "'" %}{% assign split_name = name | split: "'" %}{% for part in split_name %}{{part | capitalize}}{% unless forloop.last %}'{% endunless %}{% endfor %}{% else %}{{name | capitalize}}{% endif %}{% unless forloop.last %}{{' '}}{% endunless %}{% endfor %}

That last `unless` block has a placeholder with a single space text string because a regular space kept getting collapsed when I applied the code with a macro. If you use the code in a dynamic content placeholder, a regular space should work fine and you could even use the first code block by adding a dash inside the opening or closing tags where you want whitespace to be removed (see here for more info).

You'll probably need to test for edge cases, and the code doesn't account for user names formatted as "<last_name>, <first_name>", but hopefully it's enough to get you started.

0


댓글을 남기려면 로그인하세요.

원하는 정보를 못 찾으셨나요?

새 게시물