2

I have the following problem: I load the main layout (view) of the site in the renderOutput method which is written on the parent controller SiteController.

protected function renderOutput(){
  $menu = $this->getMenu();
  $navigation = view(env('THEME').".navigation")->with('menu',$menu)->render();
  $this->vars = array();
  $this->vars = array_add($this->vars,'navigation', $navigation);

  return view($this->template)->with($this->vars);
}

And in the child controller IndexController in the index method, I call this method. And also to display the section (section) sliders in the index method, I pass the $sliders variable to the address of the slider template.

public function index(){
    //
    $sliders = view(env('THEME').".slider")->render();
    $this->vars = array();
    $this->vars = array_add($this->vars,'sliders',$sliders); 

    return $this->renderOutput();
}

But when I use this variable in the template, I get an error. That is, the $sliders variable is not available in the template. Please tell me how to solve the problem. Thank you in advance!

Undefined variable: sliders (View: C:\Users\User\Downloads\Programs\OSPanel\domains\Corporate\resources\views\pink\index.blade.php)

1 Answer 1

1

In renderOutput() you are overwriting $this->vars that is why it is undefined.

Use:

protected function renderOutput(){
  $menu = $this->getMenu();
  $navigation = view(env('THEME').".navigation")->with('menu',$menu)->render();
  $this->vars = array_add($this->vars,'navigation', $navigation);

  return view($this->template)->with($this->vars);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.