Twig: Bug with trim()

Created on 16 Feb 2017  路  1Comment  路  Source: twigphp/Twig

I am using the trim() function with _self to get the current page without the .twig extension. The code looks like this:

{% set active = _self|trim('.twig') %}

It works fine except when the filename of the page ends with a 'T'. It that case the 'T' in the file name before the '.' gets truncated. It seems that the 'T' in the file name is getting truncated because the extension also starts with 'T'.

In other words, if the file name of the template were mypage.twig or home.twig, the above snippet would be:

active = mypage
active = home

If the file name was test.twig or contact.twig, the snippet would be:

active = tes
active = contac

Perhaps this is a bug?

Most helpful comment

That is the same with the trim function in PHP.
The argument is a string of character_mask but not a string that you want to remove.

>All comments

That is the same with the trim function in PHP.
The argument is a string of character_mask but not a string that you want to remove.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

scila1996 picture scila1996  路  3Comments

dvladimirov77 picture dvladimirov77  路  5Comments

SDPrio picture SDPrio  路  3Comments

CriseX picture CriseX  路  4Comments

reatang picture reatang  路  4Comments