Implemented Ucfirst & lcfirst for phrases

grisha2217

Active member
Hi all. For example i have phrase "uknown", i want to show phrase as "Unknown" (make first letter in upper case), why i should create new phrase to do this? i think it will be useful for developers.
 
Upvote 0
This suggestion has been implemented. Votes are no longer accepted.
You don't need to create a new phase for this, the Templater system has filters to enable you to do this. I'm going to take your example literally, but it's worth noting that the "unknown" phrase is already in title case and its default value is "Unknown".

To make the first character upper case:
Code:
{{ phrase('unknown')|to_upper('ucfirst') }}

To make the first character lower case:
Code:
{{ phrase('unknown')|to_lower('lcfirst') }}

You can remove the 'ucfirst' and 'lcfirst' arguments there if you want use strtoupper and strtolower respectively which are the default values. The "to_upper" filter also supports using 'ucwords' to make an entire phrase title case.
 
You don't need to create a new phase for this, the Templater system has filters to enable you to do this. I'm going to take your example literally, but it's worth noting that the "unknown" phrase is already in title case and its default value is "Unknown".

To make the first character upper case:
Code:
{{ phrase('unknown')|to_upper('ucfirst') }}

To make the first character lower case:
Code:
{{ phrase('unknown')|to_lower('lcfirst') }}

You can remove the 'ucfirst' and 'lcfirst' arguments there if you want use strtoupper and strtolower respectively which are the default values. The "to_upper" filter also supports using 'ucwords' to make an entire phrase title case.
What about xf 1.x?
Or you don't plain introduce new functios to xf 1.x?
 
We have strtoupper and strtolower support in XF1 but unfortunately no support for ucfirst, lcfirst or ucwords.

There's no plans to add that to XF1 at this point (it's supposed to be pretty much feature locked now) so all we'd be able recommend is upgrading to XF2 or creating your own phrases accordingly.
 
Back
Top Bottom