Layouts and View Partials
Posted: Wed Feb 04, 2009 8:58 am
My usability designer the other day requested a change that I'm not able to implement using my framework the way I've written it. They want a specific view partial to show up in different positions in the layout. So, on some screens, it should be in the main panel and on other screens, they want it in panel one.
The solution I have been using is to have page controllers instantiate a template (layout) and then send blocks (view partials) to the template. All along this has assumed only one area for blocks inside of any template. The rest of the template was all interface stuff (I thought). But now, I'm trying to come up with a good way of having the page controller send blocks to various positions in the template.
Here's an example page controller for displaying a Seat in a Committee:
I won't say I'm wed to this solution, but it's been working really well for the past two years and four applications, including the content manager for our website. What I like about the current solution is that each page controller can assemble a screen made out of existing blocks. And I can reuse the blocks throught the application.
But now, the question is how to get blocks to show up in different places in a template, instead of the templates having just one, single content area. It seems like the page controller is going to need to know what areas are available inside of a template.
How have some of you addressed this problem?
The solution I have been using is to have page controllers instantiate a template (layout) and then send blocks (view partials) to the template. All along this has assumed only one area for blocks inside of any template. The rest of the template was all interface stuff (I thought). But now, I'm trying to come up with a good way of having the page controller send blocks to various positions in the template.
Here's an example page controller for displaying a Seat in a Committee:
Code: Select all
$seat = new Seat($_GET['seat_id']);
$committee = $seat->getCommittee();
$template = new Template('two-column');
$template->blocks[] = new Block('committees/committeeInfo.inc',
array('committee'=>$committee));
$template->blocks[] = new Block('seats/seatInfo.inc',
array('seat'=>$seat));
$members = new Block('members/memberList.inc');
$members->memberList = $seat->getMembers();
$members->seat = $seat;
$template->blocks[] = $members;
echo $template->render();
But now, the question is how to get blocks to show up in different places in a template, instead of the templates having just one, single content area. It seems like the page controller is going to need to know what areas are available inside of a template.
How have some of you addressed this problem?