How to render an entry template in plugin? I have a section "Emails" which has an entry 'Welcome Email'. The template assigned for it under Section is '_email/welcome'. This works fine when viewed in frontend. But I want to render the same template in my plugin services. The code I have used is:

$template = 'welcome';
$data = 'foo';

$oldPath = craft()-&gt;path-&gt;getTemplatesPath();
$path = craft()-&gt;path-&gt;getTemplatesPath().'_email/';
craft()-&gt;path-&gt;setTemplatesPath($path);
$html = craft()-&gt;templates-&gt;render($template,$data);
$breaks = array("&lt;br /&gt;","&lt;br&gt;","&lt;br/&gt;");  
$text = str_ireplace($breaks, "\r\n", $html);
craft()-&gt;path-&gt;setTemplatesPath($oldPath);


But this gives an error "_email/_layout" not found in craft.log . What am I doing wrong ? Could anyone please help.

Thanks in advance.
If it is a frontend request

$html = craft()-&gt;templates-&gt;render('_emails/_layout.twig', $data);


and in a backend request

$oldPath = craft()-&gt;path-&gt;getTemplatesPath();
$newPath = craft()-&gt;path-&gt;getSiteTemplatesPath();
craft()-&gt;path-&gt;setTemplatesPath($newPath);
$html = craft()-&gt;templates-&gt;render('_emails/_layout.twig', array());
craft()-&gt;path-&gt;setTemplatesPath($oldPath);