Blog

Release announcements, helpful tips, and community discussion

Tip: Initials in signatures

A client asked:

How can I just use the initial of a worker’s last name in their signature?

Our templating language is based on Twig, which includes a handy syntax for extracting substrings from text:

{{"this is a string"[start:length]}}

  • start specifies the character to start from, with the first position being 0.
  • length specifies how many characters to extract.

So you could display the first initial of a worker’s last name using:



{% set first_name = "Kina" %}
{% set last_name = "Halpue" %}
{{first_name}} {{last_name[0:1]}}


Which would output:

Kina H

You can also do things like:



{% set first_name = "Kina" %}
{% set last_name = "Halpue" %}

{# Shortcut for the first letter #}
{{last_name[:1]}}

{# Everything except for the first letter #}
{{last_name[1:]}}

{# The last three letters #}
{{last_name[-3:]}}


Which outputs:

H

alpue

pue