How to load or store CodeIgniter view in variable

For using full processed view page in variable you can use CodeIgniter parser library class. Below is example code for how to get view output in variable. Process will helpful in many cases like, if you want to use mail template data in variable and pass in mail send function.

Here is use of parser library class for saving template output in variable instead of rendering in page.

//KEY-VALUE PAIR ARRAY FOR VIEW
$data = array();

//LOAD parser CLASS
$this->load->library('parser');

//GET OUTPUT IN VARIABLE
$myVar = $this->parser->parse('mail_template', $data, TRUE);

$this->parser->parse(‘mail_template’, $data, TRUE);
The first parameter contains the name of the view file, and the second parameter contains an associative array of data to be replaced in the template and third parameter for returned data instead of sent to the output class.