Also, escaping in and out of HTML like this is kinda old fashioned. These days you may want to keep your HTML separate from PHP.
Personally I limit myself to placing only variables in my HTML. So, no conditional logic in the HTML itself, which makes it very clean and easy to maintain.
If using heredoc, you can use curly brackets around variables. I.e.:
$tpl_content = array('title' => 'test', 'article_body' => 'hallo world');
$template = <<<_TEMPLATE_
<!doctype html>
<html>
<head>
<title>{$tpl_content['title']}</title>
</head>
<body>
<article>
<header>
<h1>{$tpl_content['title']}</h1>
</header>
{$tpl_content['article_body']}
</article>
</body>
</html>
_TEMPLATE_;
// End of Template
I wish I had learned this early on myself, as it could have saved me many hours of spaghetti hell.