Skip to content

Commit

Permalink
add support for kirby snippets with slots
Browse files Browse the repository at this point in the history
  • Loading branch information
tobimori committed Apr 11, 2024
1 parent 9739ca7 commit 2261f21
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Kirby\Cms\App as Kirby;
use Kirby\Template\Snippet as KirbySnippet;
use Leitsch\Blade\BladeDirectives;
use Leitsch\Blade\BladeFactory;
use Leitsch\Blade\BladeIfStatements;
Expand All @@ -22,8 +23,8 @@
'template' => function (Kirby $kirby, string $name, ?string $contentType = null) {
return new Template($kirby, $name, $contentType);
},
'snippet' => function (Kirby $kirby, $name, array $data = []): ?string {
return (new Snippet($kirby, $name, $data))->load();
'snippet' => function (Kirby $kirby, string $name, array $data = [], bool $slots = false): KirbySnippet|string {
return (new Snippet($kirby, $name, $data, $slots))->load();
},
],
'hooks' => [
Expand Down
8 changes: 4 additions & 4 deletions src/Snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

use Illuminate\Support\Facades\View;
use Kirby\Cms\App as Kirby;
use Kirby\Template\Snippet as KirbySnippet;
use Kirby\Toolkit\A;
use Kirby\Toolkit\Tpl;

class Snippet
{
public function __construct(protected Kirby $kirby, protected $name, protected array $data = [])
public function __construct(protected Kirby $kirby, protected $name, protected array $data = [], protected bool $slots = false)
{
}

public function load(): string
public function load(): string|KirbySnippet
{
$snippets = A::wrap($this->name);
$file = null;
Expand All @@ -32,7 +32,7 @@ public function load(): string
}

// vanilla PHP snippet
return Tpl::load($file, $this->data);
return KirbySnippet::factory($this->name, $this->data, $this->slots);
}

public function getFile(string $name): ?string
Expand Down

0 comments on commit 2261f21

Please sign in to comment.