Skip to content

Commit

Permalink
Adding in notempty / endnotempty (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejones authored and Log1x committed Nov 20, 2019
1 parent d187dcd commit c9bdc17
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/usage/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
24 changes: 24 additions & 0 deletions src/Directives/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,30 @@
return "<?php endif; ?>";
},

/*
|---------------------------------------------------------------------
| @notempty / @endnotempty
|---------------------------------------------------------------------
*/


'notempty' => function ($expression) {
if (Str::contains($expression, ',')) {
$expression = Util::parse($expression);

return "<?php if (! empty({$expression->get(0)})) : ?>" .
"<?php echo {$expression->get(1)}; ?>" .
"<?php endif; ?>";
}

return "<?php if (! empty({$expression})) : ?>";
},

'endnotempty' => function ($expression) {
return "<?php endif; ?>";
},


/*
|---------------------------------------------------------------------
| @instanceof / @endinstanceof
Expand Down

0 comments on commit c9bdc17

Please sign in to comment.