You don't want to add logic like this to a template file. Template files are only for displaying your block (in this case
Mage_Catalog_Block_Product_View). So what you want is a rewrite of the
Mage_Catalog_ProductController class, since this handles all requests to the product detail page.
This also has another huge benefit. As you can see in that class, it does an
initProduct call on the product helper. This method loads a product. So if you don't rewrite the controller before that point (or maybe rewrite this method itself), you first load a product, which might not exist, and then load the actual product you want, based on
$skuval. That's a performance issue, since loading a product is slow.
So if you need your product pages to "listen" to the product's SKU to load, you should rewrite the
Mage_Catalog_ProductController::_initProduct() method or the
Mage_Catalog_Helper_Product::initProduct() method, so it will also check if it can load a product based on the SKU. Keep in mind that when you rewrite the helper, the added functionality will be added to all code that uses this functionality (like
If you want to know how to rewrite stuff in Magento, Inchoo wrote a pretty useful blogpost about it back in 2013.