Skip to content

Commit

Permalink
feat: improve view() method for rockcommerce
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Dec 22, 2023
1 parent dc33123 commit c05576a
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions RockFrontend.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function rockfrontend(): RockFrontend
* @link https://www.baumrock.com
*
* @method string render($filename, array $vars = array(), array $options = array())
* @method string view($filename, array $vars = array())
* @method string view(string $file, array|Page $vars = [], Page $page = null)
*/
class RockFrontend extends WireData implements Module, ConfigurableModule
{
Expand Down Expand Up @@ -1871,10 +1871,23 @@ protected function renderFileTwig($file, $vars)

/**
* Get markup of a single view file
*/
public function ___view(string $file, array $vars = []): Html|string
{
*
* Usage:
* $rf->view('foo/bar');
* $rf->view('foo/bar', $page);
* $rf->view('foo/bar', ['foo' => 'Foo!'], $page);
*/
public function ___view(
string $file,
array|Page $vars = [],
Page $page = null,
): Html|string {
if ($vars instanceof Page) {
$page = $vars;
$vars = [];
}
$file = $this->viewFile($file);
if ($page) $vars = array_merge($vars, ['page' => $page]);
$markup = $this->render($file, $vars);
return $this->html($markup);
}
Expand Down

0 comments on commit c05576a

Please sign in to comment.