3. Layouts Blocks Templates

Created Sunday 31 August 2014

http://alanstorm.com/layouts_blocks_and_templates

http://alanstorm.com/magento_layout_directory_climbing

Blocks

Templates

Example

<?php $_productCollection=$this->getLoadedProductCollection() ?> <?php if (!$_productCollection->count()): ?> <div class="note-msg">
<?php echo $this->__("There are no products matching the selection.") ?> </div>
<?php else: ?>
public function getLoadedProductCollection()
{
return $this->_getProductCollection();
}
...

Nesting Blocks

**<!DOCTYPE html PUBLIC "-W3CDTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1-strict.dtd">**
**<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>">**
<head>
<?php echo $this->getChildHtml('head') ?>
</head>
<body class="page-popup <?php echo $this->getBodyClass()?$this->getBodyClass():'' ?>">
<?php echo $this->getChildHtml('content') ?>
<?php echo $this->getChildHtml('before_body_end') ?>
<?php echo $this->getAbsoluteFooter() ?>
</body>
</html>

The Layout

<layout version="0.1.0">
<default>
<reference name="root">
<block type="page/html" name="root" output="toHtml" template="simple_page.phtml" />
</reference>
</default>
</layout>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
**"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">**
**<html xmlns="http://www.w3.org/1999/xhtml">**
<head>
<title>Untitled</title>
<meta name="generator" content="BBEdit 9.2" />
<style type="text/css">
body {
background-color: #f00;
}
</style>
</head>
<body>

</body>
</html>
public function indexAction() {
// remove our previous echo
// echo 'Hello Index!';
$this->loadLayout();
$this->renderLayout();
}

What's Going On

Block Instantiation

<page>
<class>
Mage_Page_Block
</class>
</page>



Backlinks: