Magento – How to redirect to the home page from a template

redirecttemplate

I am in catalog\product\compare\list.phtml and I want to redirect to the homepage, like this:

if($someThing) {
    // redirect to homepage
    $this->_redirect('home'); // --> doesnt work
    $this->_redirect(Mage::getBaseUrl()); // --> doesnt work
}

I tried several things, none worked so far. How do I do it right?

Thanks!

Best Answer

From a template you can simply use the following:

Mage::app()->getResponse()->setRedirect(Mage::getBaseUrl());

I am interested as to why you are doing redirects directly in the template rather than at the controller level?