You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+15-6
Original file line number
Diff line number
Diff line change
@@ -10,9 +10,9 @@ Laravel Blade Filters
10
10
-[Internal filters](#internal-filters)
11
11
-[Testing](#testing)
12
12
13
-
Originated from [`conedevelopment/blade-filters`](https://github.com/conedevelopment/blade-filters), but with huge improvements, the original doesn't support named arguments and filter context, which are essential in my case. this library implements a custom lexer and parser to analyze filter syntax.
13
+
Originated from [`conedevelopment/blade-filters`](https://github.com/conedevelopment/blade-filters), but with lots of improvements, the original doesn't support named arguments and filter context, which are essential in my case. this library implements a lexer and parser to analyze filter syntax.
14
14
15
-
Because this library is almost refactored, this package renamed as `videni/blade-filters`, but the namespace still keeps it is.
15
+
Because this library is almost refactored and rewritten, this package renamed as `videni/blade-filters`, but the namespace still keeps it is.
{{ 'a wonderful place' | slug:separator='_', language='en' }}
27
27
```
28
28
29
-
For slug filter which provided by `\Illuminate\Support\Str`, the first argument is the value being filtered, the second argument would be the `separator`, the third would be `language`, if a argument name doesn't not exists in the slug method of `\Illuminate\Support\Str`, it will be simply ignored.
29
+
For slug filter which provided by `\Illuminate\Support\Str`, the first argument is the value being filtered, the second argument would be the `separator`, the third would be `language`, if a argument name doesn't not exists in the slug method, it will be simply ignored.
30
30
31
31
32
32
## Pass variables to filter arguments
@@ -61,19 +61,28 @@ $registry
61
61
62
62
Uncommonly, your filter may be context aware, let's assume a context like this:
63
63
64
-
A filter named `cdn_url` which generated url for an asset.
64
+
A filter named `cdn_url` which generates url for an asset.
65
65
```php
66
66
cdn_url('assets/carousel.css');
67
67
```
68
68
the domain of the CDN will change depending on the context where the filter run, the context itself is not part of the API of our filter, which the user doesn't need to worry about. you can always pass a variable to your filter as an argument following [Pass variables to filter arguments](#pass-variables-to-filter-arguments), however, the variable must be filled by the filter's user(you or someone), this is the difference between `filter context` and `filter argument`.
69
69
70
+
filter context is a string which could be a full qualified class name or a variable in Blade view, it must have method access operator( ->, :: ) suffix, an example could be the `getFilterContext` method of class `\Pine\BladeFilters\FilterProvider\StaticMacroableFilterProvider`.
71
+
72
+
```
73
+
public function getFilterContext(): string
74
+
{
75
+
return sprintf('%s::', $this->class);
76
+
}
77
+
```
70
78
## Internal filters
71
79
72
-
all static methods from `Pine\BladeFilters\BladeFilters` and `\Illuminate\Support\Str` are provided as blade filters, it is quite simple, please check its source code reference.
80
+
all static methods from `Pine\BladeFilters\BladeFilters` and `\Illuminate\Support\Str` are provided as blade filters, it is quite simple, please check its source code for reference.
0 commit comments