为我们的Hello World模块创建一个简单的HTML模板。首先我们要创建如下文件
app/design/frontend/default/default/layout/local.xml
包含以下内容
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
<helloworld_index_index>
<reference name="root">
<block type="page/html" name="root" output="toHtml" template="helloworld/simple_page.phtml"/>
</reference>
</helloworld_index_index>
</layout>
再创建如下文件
app/design/frontend/default/default/template/helloworld/simple_page.phtml
包含以下内容
<!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>
<style type="text/css">
body {
background-color:#f00;
}
</style>
</head>
<body>
<h4>Links</h4>
<?php echo $this->getChildHtml('top.links'); ?>
<?php echo $this->getChildHtml('customer_form_register'); ?>
</body>
</html>
最后,我们要在执行控制器里面调用布局文件,开始输出HTML。修改执行方法如下
public function indexAction() {
//remove our previous echo
//echo 'Hello Index!';
$this->loadLayout();
$this->renderLayout();
}