I'm not familiar with Widgets, so this may or may not be helpful.
If you are writing a plugin, generally you don't need to parse your own template code. Simply call:
$variables = array(array('name' => 'adrian'));
$this->EE->TMPL->parse_variables($template, $variables);
Which will parse any variables, loops, or conditionals inside your template. Third party plugins in the tagdata code will be left intact, and parsed automatically later on in the EE parse order.
However, if you really need to fully parse your own template code (for example, I have used this when sending emails), you need to set up your own instance of the EE template library, and duplicate some of the code which EE uses internally (this is pretty much the code we use in Store):
$email_body = '<!-- your template data here -->';
$tag_vars = array(array('name' => 'adrian')); // simple variables to parse directly
// back up existing TMPL class
$this->EE->load->library('template');
$OLD_TMPL = isset($this->EE->TMPL) ? $this->EE->TMPL : NULL;
$this->EE->TMPL = new EE_Template();
// parse simple variables
$email_body = $this->EE->template->parse_variables($email_body, $tag_vars);
// pretty lame that we need to manually load snippets
$result = $this->db->select('snippet_name, snippet_contents')
->where('site_id', $this->config->item('site_id'))
->or_where('site_id', 0)
->get('snippets')->result_array();
$snippets = array();
foreach ($result as $row) {
$snippets[$row['snippet_name']] = $row['snippet_contents'];
}
// merge snippets into global variables
$this->EE->config->_global_vars = array_merge($this->EE->config->_global_vars, $snippets);
// parse email contents as complete template
$this->EE->TMPL->parse($email_body);
$email_body = $this->EE->TMPL->parse_globals($this->EE->TMPL->final_template);
// restore old TMPL class
$this->EE->TMPL = $OLD_TMPL;
return $email_body; // this is your parsed template
echo
that into the output of the widget. I think that I have found my answer (see below). Please let me know if there are good reasons to avoid the approach that I suggest below: