Laravel Blade Filters Package

Laravel Blade Filters Package

Blade Filters is a package by Gergo D. Nagy that adds the concept of filters to your blade templates. If you’re familiar with Django’s templating system or Symfony’s Twig templating language, the concept of a filter looks like this:

{{ 'john' | ucfirst }} // John

Alternatively, you could write the same thing like this in Blade without the concept of filters:

{{ ucfirst('john') }}

Chained usage is where I personally feel filters begin to shine over function calls:

{{ 'john' | ucfirst | substr:0,1 }} // J

{{ substr(ucfirst('john'), 0, 1) }}

More usefully, here’s how you’d use filters with a template variable:

{{ $currentUser->name | ucfirst | substr:0,1 }}

Finally, this package provides filters that leverage built-in Laravel APIs:

{{ 'This is a title' | slug }} // this-is-a-title

{{ 'This is a title' | title }} // This Is A Title

{{ 'foo_bar' | studly }} // FooBar

To learn more about this package—including installation instructions—check out the source code on GitHub at thepinecode/blade-filters. Also, the package author Gergo wrote a detailed article that explains how to build a custom ViewServiceProvider that you should check out!


Filed in: Laravel Packages


Newsletter

Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Laravel Engineer
Remote okay (must already live in USA)
Hawthorne Effect
Senior Software Engineer (Remote - Contract)
Remote
Koodi Systems
PHP Developer
Pittsburgh / Remote
Sequoia Waste Solutions
Software Developer
Eindhoven
Simac IDS
Application Developer Level II (CakePHP / MySql / Vue.js)
Lancaster, PA
Harbor Compliance
FULL STACK LARAVEL DEVELOPER
LONDON - WEST END
AMPERSAND HEATLH
Mid/Senior Laravel Developer - U.S. Only
Kenner, Louisiana
Profit Miner Technologies