Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
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):
<?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(); ?>
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?
I think that simple Composite/Component attachment of renderers is the best overall solution. It is essentially hierarchical templates, but you can attach an object with a render() method at any point and it will work just like attaching a scalar. It is a little more work for simple things, but the complexity does not increase no matter how complex the hierarchy becomes. And it makes tooling simple.
Ninja, check the Zend Framework Incubator on subversion - it probably will not be exactly like Django (or anything else) but Zend_View Enhanced/Zend_Layout was approved for development. I will refer you here just in case you're curious why I'm not actually committing any of it personally . Nothing I have proposed to ZF so far has come close to working out as planned.
The Block extract from Django will be implemented as a Placeholder helper in Zend_View. General placeholders for transporting data between templates and a parent Layout will also be made available. Look up the Zend_View Enhanced proposal for what else is incoming. I think most of the proposal text is still mine....
If you have any comments at all about what's managed to make it to Incubator I can pass them on to Matthew.
arborint - I have seen systems like that... in fact it's pretty much how mine works as is.
Maugrim - thanks... I'll take a look
kyberfabrikken, that is exactly what I was looking to do. Like you said the syntax isn't the same... but I like it. I'll have to give it a try. Thank you very much.
Maugrim_The_Reaper wrote:I will refer you here just in case you're curious why I'm not actually committing any of it personally . Nothing I have proposed to ZF so far has come close to working out as planned.
As you know, I bowed out several months back after pushing a lot of ideas into the Core and MVC. The process is definitely not one of engagement or letting people develop their ideas -- and it shows. The View especially should have been redesigned and an adapter done for BC.
I prefer to think the ZF Proposal Process is itself bastardized though.
The View especially should have been redesigned and an adapter done for BC.
Never going to happen. It's taken months just to get some simple changes added from ZVE; anything more than a few lines would be killed on the spot. You'd have to time travel to when the ZF adopted the Solar View class to stop it.