Skip to content

Commit

Permalink
Exclude sections that start with a _
Browse files Browse the repository at this point in the history
  • Loading branch information
maddhatter committed Jun 24, 2022
1 parent 62f9433 commit e088b70
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Note: If there are multiple paths defined in your `config/view.php`'s `paths` ar
php artisan make:view path.to.your.view -e path.to.parent.view
```

You can optionally extend another view by adding the `-e` parameter and providing the name of the view you want to extend. It will parse the parent view for `@yield()` directives and create the corresponding `@section` / `@endsection` tags.
You can optionally extend another view by adding the `-e` parameter and providing the name of the view you want to extend. It will parse the parent view for `@yield()` directives and create the corresponding `@section` / `@endsection` tags. To exclude a section from automatic creation, begin the name with an underscore, e.g.: `_meta`

#### Example

Expand All @@ -51,6 +51,7 @@ resources/views/layouts/master.blade.php
<html>
<head>
<meta charset="UTF-8">
@yield('_meta')
</head>
<body>
Expand Down
5 changes: 5 additions & 0 deletions src/MakeViewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ protected function renderView($extends)

if (preg_match_all('/\B@(\w+)([ \t]*)(\( ( (?>[^()]+) | (?3) )* \))?/x', $parent, $matches)) {
for ($i = 0; $i < count($matches[1]); $i++) {
// Skip sections starting w/ a _
if (str_starts_with($matches[4][$i], '\'_')) {
continue;
}

switch ($matches[1][$i]) {
case 'yield':
case 'section':
Expand Down

0 comments on commit e088b70

Please sign in to comment.