Skip to content

Fix first filter for numbers#966

Merged
willrowe merged 1 commit into
twigjs:masterfrom
greymoth-jp:fix-first-filter-numbers
Jun 29, 2026
Merged

Fix first filter for numbers#966
willrowe merged 1 commit into
twigjs:masterfrom
greymoth-jp:fix-first-filter-numbers

Conversation

@greymoth-jp

Copy link
Copy Markdown
Contributor

The last filter was updated in 74e681a to return the last digit of a number, matching TwigPHP, but its counterpart first never got the same treatment. As a result {{ 130|first }} renders an empty string while {{ 130|last }} renders 0.

In TwigPHP both filters run the value through slice, which casts a scalar to a string before taking the substring, so first of a number is its first digit. This adds the missing Number branch to first, mirroring what last already does, and adds a test next to the existing last number test.

`last` returns the last digit of a number since 74e681a, but `first`
fell through to undefined and rendered an empty string. In TwigPHP both
filters go through slice, which casts a scalar to a string, so
`130|first` should yield "1". Add the missing Number branch to mirror
`last`.
@willrowe
willrowe merged commit eb253e1 into twigjs:master Jun 29, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants