Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Add Str::limit method #58

Closed
wants to merge 2 commits into from

Conversation

martialblog
Copy link
Member

This method truncates the given string to the specified length. Use cases are long titles and descriptions in text shown to the user, that would overload the screen.

Example:

$title = Str::limit('Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 10);

$title == 'Lorem ipsu...';

I often find myself in need to truncate output such as titles and descriptions. Adding this to the stdlib would be nice, so it can be reused.

Might also be useful in existing Modules, for example:

businessproc

This method truncates the given string to the specified length.
Use cases are long titles and descriptions in text shown to the user,
that would overload the screen.

Example:

```
$title = Str::limit('Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 10);

$title == 'Lorem ipsu...';
```
@cla-bot cla-bot bot added the cla/signed label Jul 12, 2024
@nilmerg
Copy link
Member

nilmerg commented Jul 12, 2024

That's usually a job for the browser. The reason is that it knows the user's device and its screen size or window size. The backend cannot impose useful constraints to displayed text. It's either often too long or too short if done this way.

We have the .text-ellipsis() mixin as part of ipl-web, hence I see no real advantage for this method in the Str class here.

@martialblog
Copy link
Member Author

Good to know. Didn't know that existed and how to find it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants