I\'m trying to include the following code block (which contains some dynamic values) in my header view if certain conditions are met.
Load the JS view in the controller and pass it over to the controller.
$jsview = $this->load->view('view_name', array(), true);
Note that the third parameter is set to true. That will return the view to you instead of outputting the view to the screen.
Then, pass it over to your main view.
$data['js'] = $jsview;
$this->load->view('mainview',$data);
That is a better MVC approach as the logic remains in the controller.