CMS page add block magento

andys picture andys · Apr 10, 2012 · Viewed 36.3k times · Source

I have in CMS->page "home page" file. In content i am writing line like this:

{{block type="myfolder/newfile" template="myfolder/newfile.phtml"}}

I want to render in content file newfile.phtml. What i am doing wrong ?

My new file is under: app\design\frontend\default\themeas\template\myfolder\newfile.phtml

Answer

Anthony Raymond picture Anthony Raymond · Apr 10, 2012

You need to give your block a name. That's how Magento will reference the block. Also, your block type must be valid in order for the block to render. For default blocks try using type="core/template"

Your new code should look like this:

{{block type="core/template" name="my.block.name" template="myfolder/newfile.phtml"}}

Another note about the type attribute, its not actually a directory/file structure, rather, it's a URI that is mapped with the Magento autoloader. "Core" relates back to the Mage_Core_Block_Core class (under the app/code/core/Mage/Core directory) and then the info after the slash relates to the folders inside of that directory. So type="core/template" resolves to this class Mage_Core_Block_Core_Template which is located at app/code/core/Mage/Core/Block/Template.php. All the type attribute is doing is telling Magento which methods you need to load inside of your block.

A couple other block types you can try are:

For Product Lists: catalog/product_list

For Text Lists (blocks that automatically render out child blocks): core/text_list

For Category Blocks: catalog/category_view

There are plenty more, a good way to find new ones is to look at a block that does a similar action to what you are trying to do, and find where it is defined in the XML.