Hi,
I will try and find some good examples of this as soon as possible. I learnt about them through a quick tutorial a long time back and just been using them ever since.
The basic idea is to define a "Master Page" (like a layout I guess in other frameworks and applications...including the likes of Joomla). This might look something like this:
- Code: Select all
<%@ Master %>
<html>
<body>
<h1>Site Name</h1>
<div class="wrapper">
<div class="menu">
<asp:ContentPlaceHolder id="MainMenu" runat="server"></asp:ContentPlaceHolder>
</menu>
<div class="mainContent">
<asp:ContentPlaceHolder id="MainContent" runat="server"></asp:ContentPlaceHolder>
</div>
<div class="sideContent">
<asp:ContentPlaceHolder id="SideContent" runat="server"></asp:ContentPlaceHolder>
</div>
</div>
</body>
</html>
You can then have a View file /protected/view/example.html (following DooPHP locations) which can then redefine what content to place into each placeholder. So you have something like:
- Code: Select all
<%@ Page MasterPageFile="master1.master" %>
<asp:Content ContentPlaceHolderId="MainContent" runat="server">
<h2>My Main Content for this Page</h2>
<p>Some text</p>
</asp:Content>
<asp:Content ContentPlaceHolderId="SideContent" runat="server">
<h3>Side Content</h3>
<p>Some text</p>
</asp:Content>
The nice thing about this is the Views just specify what to show in a place holder. They do not care 'where this will go' within the layout specified in the master page. The master page can also define default content for a place holder so you can opt to override the content or just leave it alone depending on what you want that View file to do. You can also define a placeholder and leave its default content empty and also not define it in the View file and it will essentially appear not to exist but then a SpecialView could still define content for this so the homepage for example could contain an extra advert at the top of the page for example.
Additionally you can add code behind the MasterPage so it could for example determin what Site Theme the user is using and then map all of the css files to /theme/USER_CHOICE/styles.css and provide functions for outputting the page title which views could then call to set there page title.
You can also nest Master Pages within one another so you would define MasterPage2 to set a placeholder of MasterPage1 to now contain 2 placeholders (and some extra markup) then another View say Blog.html would use MasterPage2 which takes the MasterPage1 layout, then applies its changes and then fills the placeholders with the Views Content. This could be handy when you maybe want to have a variation of the main sites layout for a given section of the website.
This page has an introduction which partly demonstrates the basic use of a Master Page using VB.NET :
http://weblogs.asp.net/scottgu/archive/2006/01/17/Data-Tutorial-_2300_2_3A00_-Building-our-Master-Page-and-Site-Navigation-Structure.aspx (up until about Figure 7)
I have not used the Zend_Layout (I decided the framework was to bloated and slow for my liking) but I think this has a similar approach and the documentation here :
http://framework.zend.com/manual/en/zend.layout.quickstart.html is similar to what I am looking to achieve / see in DooPHP.
Essentially I just want to be able to define a site layout without ever creating a View...and then the View is doing what it should be...which is "The Content For X is ... and the Content for Y is ..." and just the formatting it really must include for achieving this. Maybe some sort of $this->renderLayout('masterLayout.html', 'myPageContent', ...); whereby the render would take the masterLayout.html and its placeholders + default value and then place into it the content from the myContentPage.html file.
Something like protected/layouts/MastePage.html :
- Code: Select all
<html>
<body>
<h1>My Site</h2>
<div class="mainContent">
<!-- The content for this placeholder MUST be provided in the view -->
<!-- required_place_holder::XYZ -->
</div>
<div class="advert">
<!-- This placeholder is optional and the View does not have to provide any content. If none is provided we just use the default -->
<!-- optional_place_holder::ABC -->
<img src="defaultAdvertImage" />
<!-- end_optional_place_holder::ABC -->
</div>
</body>
</html>
Then in protected/view/myPage.html
- Code: Select all
<!-- content::XYZ -->
<p>The pages content</p>
<!-- endcontent::XYZ -->
And if I wanted to also override the advert I could have
- Code: Select all
<!-- content::XYZ -->
<p>The pages content</p>
<!-- endcontent::XYZ -->
<!-- content::ABC -->
<p>Some text advert instead</p>
<!-- endcontent::ABC -->
This would be great when you want to offer different site layouts for say a PC and an iPhone where you can have different site layouts and classes but you would probably still want the same view information.
Hope this helps clear up what I am thinking about?
Richard
Note: code samples my not be 100% accurate.