diff --git a/docs/usage/helpers.md b/docs/usage/helpers.md index 4257c2e..ab97bfe 100644 --- a/docs/usage/helpers.md +++ b/docs/usage/helpers.md @@ -66,6 +66,22 @@ Alternatively, you can pass the output as a second parameter: @isnotnull($variable, 'There is something here.') ``` +## @notempty + +`@notempty` is a simple conditional that displays the specified output if the parameter passed exists and is not empty. It can be closed using `@endnotempty`. + +```php +@notempty($variable) + There is something here. +@endnotempty +``` + +Alternatively, you can pass the output as a second parameter: + +```php +@notempty($variable, 'There is something here.') +``` + ## @instanceof `@instanceof` checks if the first parameter is an instance of the second parameter. It can be closed using `@endinstanceof`. diff --git a/src/Directives/Helpers.php b/src/Directives/Helpers.php index e96205b..6b440a7 100644 --- a/src/Directives/Helpers.php +++ b/src/Directives/Helpers.php @@ -91,6 +91,30 @@ return ""; }, + /* + |--------------------------------------------------------------------- + | @notempty / @endnotempty + |--------------------------------------------------------------------- + */ + + + 'notempty' => function ($expression) { + if (Str::contains($expression, ',')) { + $expression = Util::parse($expression); + + return "get(0)})) : ?>" . + "get(1)}; ?>" . + ""; + } + + return ""; + }, + + 'endnotempty' => function ($expression) { + return ""; + }, + + /* |--------------------------------------------------------------------- | @instanceof / @endinstanceof