{{block type="cms/block" block_id="identificador"}}
A la plantilla:
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('block6')->toHtml() ?>
Pot aparèixer un banner sobre del llistat de les categories
Editem la categoria → CMS Block i decidim quin associem
També podem associar Display Mode:
app/design/frontend/tu_tema/tu_tema/layouts/customer.xml
<customer_logged_out>
<reference name="top.links">
<action method="addLink" translate="label title" module="customer"><label>Log In</label><url helper="customer/getLoginUrl"/><title>Log In</title><prepare/><urlParams/><position>100</position></action>
</reference>
<remove name="wishlist_sidebar"></remove>
<remove name="reorder"></remove>
<reference name="right">
<block type="customer/form_login" name="mini_login" template="customer/form/mini.login.phtml" before="-"/>
</reference>
</customer_logged_out>
app/design/frontend/tu_tema/tu_tema/layout/catalog.xml
<reference name="right">
<block type="newsletter/subscribe" name="left.newsletter" template="newsletter/subscribe.phtml"/>
<block type="core/template" before="cart_sidebar" name="catalog.compare.sidebar" template="catalog/product/compare/sidebar.phtml"/>
<block type="core/template" name="right.permanent.callout" template="callouts/right_col.phtml"/>
</reference>
Per exemmple:
<block type="customer/form_login" name="mini_login" template="customer/form/mini.login.phtml" before="-"/>
Com puc saber la possició que es troba per sobre? Editem el .phmtl que carga el bloc i mirem a on es troba:
$this->getChildHtml("nombre_bloque")
Estructura de directoris
app/code/local/Zikzakmedia/Randomproduct app/code/local/Zikzakmedia/Randomproduct/Block/View.php app/code/local/Zikzakmedia/Randomproduct/etc/config.xml app/design/frontend/default/default/randomproduct/view.phtml app/etc/modules/Zikzakmedia_Randomproduct.xml
app/code/local/Zikzakmedia/Randomproduct/Block/View.php
<?php
class Zikzakmedia_Randomproduct_Block_View extends Mage_Core_Block_Template {
public function myFunction(){
return "Hello World!";
}
}
?>
Si hem de crear un block per a productes, hem d'extendre la classe de Mage_Catalog_Block_Product_Abstract
class Zikzakmedia_Randomproduct_Block_View extends Mage_Catalog_Block_Product_Abstract
app/code/local/Zikzakmedia/Randomproduct/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Zikzakmedia_Randomproduct>
<version>0.1.0</version>
</Zikzakmedia_Randomproduct>
</modules>
<global>
<blocks>
<randomproduct>
<class>Zikzakmedia_Randomproduct_Block</class>
</randomproduct>
</blocks>
</global>
</config>
app/design/frontend/default/default/randomproduct/view.phtml
<p>Example:</p> <?php echo $this->myFunction(); ?>
app/etc/modules/Zikzakmedia_Randomproduct.xml
<?xml version="1.0"?>
<config>
<modules>
<Zikzakmedia_Randomproduct>
<active>true</active>
<codePool>local</codePool>
</Zikzakmedia_Randomproduct>
</modules>
</config>
Editem el contingut de CMS:
{{block type="randomproduct/view" template="randomproduct/view.phtml"}}
Si ho volem al XML de les vistes afegim al config.xml del mòdul:
<frontend>
<layout>
<updates>
<simpletags>
<file>simpletags.xml</file>
</simpletags>
</updates>
</layout>
</frontend>