I'm currently using the following code to create variable tags for use in the Magento CMS to print out various portions of dynamic data for a product:
<?php
$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $this->getData('sku'));
$_categories = Mage::getModel('catalog/category')->loadByAtribute('id', $this->getData('id'));
switch($this->getData('valuetype')){
case "retail":
echo number_format($_product->getPrice(), 2, '.', ',');
break;
default:
case "final":
echo number_format($_product->getFinalPrice(), 2, '.', ',');
break;
case "diffDollar":
$difference = $_product->getPrice() - $_product->getFinalPrice();
echo number_format($difference, 2, '.', ',');
break;
case "diffPercent":
$difference = (1 - ($_product->getFinalPrice() / $_product->getPrice())) * 100;
echo number_format($difference, 0, '.', ',');
break;
case "prodName":
echo ($_product->getName());
break;
case "urlPath":
$prodName = ($_product->getName());
$prodName = strtolower($prodName);
$path = explode(" ", $prodName);
$path = implode("-", $path);
echo $path;
break;
case "catName":
$catName = ($_categories->getName());
echo $catName;
break;
}
?>
Inside of the CMS I would use the following to bring in the data for $_categories:
{{block type="catalog/category" id="176" template="catalog/product/cmsprice.phtml" valuetype="catName"}}
For $_product I would use:
{{block type="catalog/products" sku="1000145" template="catalog/product/cmsprice.phtml" valuetype="retail"}}
Using $_product works perfectly but when I try to use $_categories to print out the category name, the page from the CMS does not render on the homepage but the rest of the page appears and there are no errors displayed.
I feel like I'm close to getting this but can't see what I'm missing. Any help would be greatly appreciated