Splitting a Twig Variable into 2 Variables I want to split my variable into two new variables before and after the dash character "-".

How do I adjust my code below to enable this to happen?

{% set name = 'first-last' %}
{% set firstNameSlug = name|split('-')[1] %}
{% set lastNameSlug = name|split('-')[2] %}

{{ firstNameSlug }}
{{ lastNameSlug }}
If I'm following you, arrays are 0-indexed, so this would work (with a bit of cleanup).

{% set names = 'first-last'|split('-') %}
{% set firstNameSlug = names[0] %}
{% set lastNameSlug = names[1] %}

{{ firstNameSlug }}
{{ lastNameSlug }}