luya\web\Controller::renderLayout PHP Method

renderLayout() public method

For example you have a e-store module with a header which returns the basket you can use the module layout in all the actions to retrieve the same header. Example e-store controller class:. php class EstoreController extends \luya\base\Controller { public function actionIndex() { return $this->renderLayout('index', ['content' => 'This is my index content in variabel $content.']); } public function actionBasket() { return $this->renderLayout('basket', ['otherVariable' => 'This is a variable for the basket view file in variable $otherVariable.']); } } The example layout file which is located in @app/views/module/layout could look something like this: php
  • E-Store Frontpage
  • Basket
public renderLayout ( string $view, array $params = [] ) : string
$view string The name of the view file
$params array The params to assign into the view file.
return string Rendered template wrapped by the module layout file.
    public function renderLayout($view, $params = [])
    {
        $content = $this->view->renderFile($this->getViewPath() . '/' . $view . '.php', $params, $this);
        return $this->render($this->getModuleLayoutViewPath() . $this->module->moduleLayout, ['content' => $content]);
    }