Skip to content

Commit

Permalink
update App::render
Browse files Browse the repository at this point in the history
  • Loading branch information
aheinze committed Jul 25, 2023
1 parent 99aa46f commit 451e4a9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/Lime/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,18 +545,18 @@ public function trigger(string $event, array $params=[]): self {
*/
public function render(string $view, array $slots = [], bool $print = false): string {

$this->trigger('app.render.view', [&$view, &$slots]);

if (\is_string($view) && $view) {
$this->trigger("app.render.view/{$view}", [&$view, &$slots]);
}

$layout = $this->layout;

$this->trigger('app.render.view', [&$view, &$slots]);

if (\strpos($view, ' with ') !== false ) {
list($view, $layout) = \explode(' with ', $view, 2);
}

if (\is_string($view) && $view) {
$this->trigger("app.render.view/{$view}", [&$view, &$slots]);
}

if (\strpos($view, ':') !== false && $file = $this->path($view)) {
$view = $file;
}
Expand All @@ -565,22 +565,22 @@ public function render(string $view, array $slots = [], bool $print = false): st
$layout = $from;
};

$render = function($view, $slots) use($setViewLayout) {
\extract((array)$slots);
$render = function($view, $viewSlots) {
\extract((array)$viewSlots);
\ob_start();
include $view;
return \ob_get_clean();
};

$contents = $render($view, $slots);
$contents = $render($view, array_merge($slots, ['setViewLayout' => $setViewLayout]));

if ($layout) {

if (\strpos($layout, ':') !== false && $file = $this->path($layout)) {
$layout = $file;
}

$contents = $render($layout, ['content_for_layout' => $contents]);
$contents = $render($layout, array_merge($slots, ['content_for_layout' => $contents]));
}

if ($print) {
Expand Down

0 comments on commit 451e4a9

Please sign in to comment.