Skip to content

Commit f159178

Browse files
feat: allow setting of template data
1 parent 869b050 commit f159178

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/Html/Builder.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class Builder
6262

6363
protected array $additionalScripts = [];
6464

65+
protected array $templateData = [];
66+
6567
public function __construct(public Repository $config, public Factory $view, public HtmlBuilder $html)
6668
{
6769
/** @var array $defaults */
@@ -158,7 +160,13 @@ protected function template(): string
158160

159161
$template = $this->template ?: $configTemplate;
160162

161-
return $this->view->make($template, ['editors' => $this->editors, 'scripts' => $this->additionalScripts])->render();
163+
return $this->view->make(
164+
$template,
165+
array_merge(
166+
['editors' => $this->editors, 'scripts' => $this->additionalScripts],
167+
$this->templateData,
168+
)
169+
)->render();
162170
}
163171

164172
/**
@@ -263,4 +271,15 @@ public function addScript(string $view): static
263271

264272
return $this;
265273
}
274+
275+
public function templateData(array|\Closure $data = []): static
276+
{
277+
if ($data instanceof \Closure) {
278+
$data = $data($this) ?? [];
279+
}
280+
281+
$this->templateData = $data;
282+
283+
return $this;
284+
}
266285
}

0 commit comments

Comments
 (0)