YII2 - Rendering a view dynamically with parameters

189 Views Asked by At

I'm trying to create a system were I can define in admin, dynamic sidebars. There are a few things I will have in the sidebar and one is to render a view. Doing it without parameters and simple parameters, so like this

<?php 
  $view_filename = $component->view_filename // something like "my_sidebar.php";
  $param1 = $component->param1 // Something like "2"
          
  echo $this->render("/widgets/$view_filename", ['type' => $param1]); 
?>

is easy, but I'm having issues passing a model because I can't doing something like

<?php 
  $view_filename = $component->view_filename // something like "my_model_sidebar.php";
  $param1 = $component->param1 // Something like "$model"
          
  echo $this->render("/widgets/$view_filename", ['model' => $param1]); 
?>

Is it possible to do what I require? I'm guessing this is stupidly easy but I just don't get it!

0

There are 0 best solutions below