generated from tomdavies/craft-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved: structure, functionality and consistency of twig extension (#…
…12)
- Loading branch information
Showing
12 changed files
with
131 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# String Helpers | ||
|
||
Toolbelt provides a wide number of Twig filters and functions for manipulating strings. | ||
|
||
## Wrapped PHP Functions | ||
|
||
The following functions/filters are wrappers for PHP native functions: | ||
|
||
| Twig name | Available in Twig as | Wrapped function / signature | Docs | | ||
|-------------|----------------------|--------------------------------------------------------------------------------|------------------------------------------------------------| | ||
| `parse_url` | `function` | `parse_url(string $url, int $component = -1): int\|string\|array\|null\|false` | [🔗](https://www.php.net/manual/en/function.parse-url.php) | | ||
| `dirname` | `function` | `dirname(string $path, int $levels = 1): string` | [🔗](https://www.php.net/manual/en/function.dirname.php) | | ||
| `pathinfo` | `function` | `pathinfo(string $path, int $flags = PATHINFO_ALL): array\|string` | [🔗](https://www.php.net/manual/en/function.pathinfo.php) | | ||
| `md5` | `function`, `filter` | `md5(string $string, bool $binary = false)` | [🔗](https://www.php.net/manual/en/function.md5.php) | | ||
|
||
## Wrapped `craft\helpers\StringHelper` Functions | ||
|
||
The following functions/filters are wrappers for functions in Craft's [`craft\helpers\StringHelper`](https://docs.craftcms.com/api/v4/craft-helpers-stringhelper.html) class: | ||
|
||
| Twig name | Available in Twig as | Wrapped method / signature | Docs | | ||
|---------------------|----------------------|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------| | ||
| `UUID` | `function` | `UUID(): string` | [🔗](https://docs.craftcms.com/api/v4/craft-helpers-stringhelper.html#method-uuid) | | ||
| `basename` | `function`, `filter` | `basename(string $path, string $suffix = ''): string` | [🔗](https://docs.craftcms.com/api/v4/craft-helpers-stringhelper.html#public-methods) | | ||
| `humanize` | `function`, `filter` | `humanize(string $str): string` | [🔗](https://docs.craftcms.com/api/v4/craft-helpers-stringhelper.html#method-humanize) | | ||
| `slugify` | `function`, `filter` | `slugify(string $str, string $replacement = '-', ?string $language = null): string` | [🔗](https://docs.craftcms.com/api/v4/craft-helpers-stringhelper.html#method-slugify) | | ||
| `titleize` | `function`, `filter` | `titleize(string $str, ?[] $ignore = null): string` | [🔗](https://docs.craftcms.com/api/v4/craft-helpers-stringhelper.html#method-titleize) | | ||
| `titleizeForHumans` | `function`, `filter` | `titleizeForHumans(string $str, ?[] $ignore = null): string` | [🔗](https://docs.craftcms.com/api/v4/craft-helpers-stringhelper.html#method-titleizeForHumans) | | ||
|
||
## Extra String Helpers | ||
|
||
The following functions/filters are custom to Toolbelt: | ||
|
||
| Twig name | Available in Twig as | Signature | Docs | | ||
|----------------------|----------------------|------------------------------------------|-------------------------------------------------------------------------------------| | ||
| `stringify()`, `s()` | `function`, `filter` | stringify(string $str): \Stringy\Stringy | Converts a string to a [Stringy instance](https://github.com/danielstjules/Stringy) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace zaengle\Toolbelt\Helpers; | ||
|
||
class DataHelper | ||
{ | ||
public static function json_decode(string|array $value, bool $assoc = false, int $depth = 512, int $flags = 0): mixed | ||
{ | ||
if (is_array($value)) { | ||
return $value; | ||
} | ||
|
||
return json_decode(html_entity_decode($value), $assoc, $depth, $flags); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace zaengle\Toolbelt\Helpers; | ||
|
||
class StringHelper | ||
{ | ||
public static function md5(string $string, bool $binary = false): string | ||
{ | ||
return md5($string, $binary); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters