Zend_View - layout like django
Posted: Tue Oct 02, 2007 6:48 pm
I have come to really like how django's template engine works and would like to try and implement it in PHP / Zend Framework. The way it works is you render a template that "extends" the base layout and then define each block inside your template. A typical template might look like this (if we were to pull it off in PHP):
The base template would look something like...
The problem is that I can't think of any way to do this. I've been racking my brain and trying things out... nothing seems to work. It seems like I'd need to implement some type of output buffering so that I could capture text in between startBlock and endBlock but even then... how would I know where to save it to? Anybody know how I could go about this? Impossible?
Code: Select all
<?php $this->extends('base.html'); ?>
<?php $this->startBlock('head'); ?>
<link rel="stylesheet" href="<?php echo $this->stylesheet; ?>" type="text/css" media="screen">
<?php $this->endBlock(); ?>
<?php $this->startBlock('content'); ?>
<h2>Welcome to my page!</h2>
<p>Mauris mi. Duis congue varius eros. Mauris odio erat, facilisis non, gravida nec, sollicitudin vitae, mi. Sed dapibus ipsum tempor lacus. Mauris dapibus rhoncus purus. Nam ut lorem et velit malesuada venenatis. Suspendisse tincidunt. Fusce posuere tortor sit amet est. Etiam vel nibh in lectus gravida sagittis. Praesent a magna at odio luctus vulputate.</p>
<?php $this->endBlock(); ?>Code: Select all
<?php echo $this->config->doctype; ?>
<html>
<head>
<meta http-equiv="Content-Type" content="<?php echo $this->config->content_type; ?>; charset=<?php echo $this->config->charset; ?>" />
<title><?php if ($this->title) { echo $this->title; } else { echo $this->config->name; } ?></title>
<link rel="stylesheet" href="<?php echo $this->MEDIA; ?>styles/screen.base.css" media="screen" type="text/css">
<?php $this->startBlock('content'); ?> Default head stuff goes here <?php $this->endBlock(); ?>
</head>
<body>
<h1><?php echo $this->config->name; ?></h1>
<?php echo $this->render('menu.phtml'); ?>
<?php $this->startBlock('content'); ?> Default content goes here <?php $this->endBlock(); ?>
</body>
</html>