You cannot change the template for a static block because the static block does not have a template. Take a look at the method: Mage_Cms_Block_Block::_toHtml()
. The _toHtml()
method is used to render any block object, and in the case of the cms blocks it only renders the content of the block.
If you want to wrap the content of any cms block in some markup you can try this:
{{block type="core/template" template="custom/block.phtml" block_id="some_block_id"}}
And in the file custom/block.phtml
do this:
<?php
$block = Mage::app()->getLayout()->createBlock('cms/block')->setBlockId($this->getBlockId()); //retrieve the cms block with the id set on this layout block
$html = $block->toHtml();//in this var you have the content of the cms block
?>
<?php if ($html) : //this is needed to avoid additional markup if the cms block is empty?>
<div class="some-class">
<div class="some-other-class">
<?php echo $html;//actuall cms block?>
</div>
</div>
<?php endif;?>
I hope this is what you needed.
If there is a common functionality/method which you might going to use for other modules as well, better you add those methods inside a helper class.
Now for this instance, you can use either block or helper to write method in order to retrieve a set of simple products. But my suggestion is use the block to retrieve data you want and call the block (block method) in home page.
I'll elaborate the answer here itself.
Suppose we have a module name "Home" inside a namespace as "Test".
I hope you know how to create module activation file, so I'll eliminate it here.
So the config.xml is like this:
app\code\local\Test\Home\etc\config.xml
<?xml version="1.0"?> <config>
<modules>
<Test_Home>
<version>0.1.0</version>
</Test_Home>
</modules>
<frontend>
<routers>
<home>
<use>standard</use>
<args>
<module>Test_Home</module>
<frontName>home</frontName>
</args>
</home>
</routers>
<layout>
<updates>
<home>
<file>home.xml</file>
</home>
</updates>
</layout>
</frontend>
<global>
<blocks>
<home>
<class>Test_Home_Block</class>
</home>
</blocks>
<models>
<home>
<class>Test_Home_Model</class>
</home>
</models>
</global>
<admin>
<routers>
<home>
<use>admin</use>
<args>
<module>Test_Home</module>
<frontName>home</frontName>
</args>
</home>
</routers>
</admin>
</config>
And the block file is like below:
app\code\local\Test\Home\Block\Featuredproducts.php
<?php
class Test_Home_Block_Featuredproducts extends Mage_Core_Block_Template{
public function _construct() {
parent::_construct();
$this->setTemplate('test/featured_products.phtml');
}
public function getFeaturedProducts()
{
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect("*")
->addFieldToFilter('status','1')
->addFieldToFilter('visibility',array('in' => array(2,4))); // 2 = Search, 4 = Catalog, Search
return $collection;
}
}
Inside template file name as "featured_products.phtml"
app\design\frontend\default\home\template\test\featured_products.phtml
Now we can call getFeaturedProducts method which is written on the block.
$product_collection = $this->getFeaturedProducts();
Hope this answer will help you.
Best Answer
I have created one custom module for this
and we have specified the our filter to magento by adding the following code in config.xml page
Then create the file
[Namespace]/[Module]/Model/Template/Filter.php
Note: here the function name is
helperDirective
. if you that to{{custom }}
so the function name willcustomDirective
(i.e,{{youname}}Directive
)Then I have use 3 parameters for this.
So you can call your helper function by following way
here
I have created this module by following this tutorial