How to make master pages in php
? Like a Layout.cshtml
(and RenderBody()
) in ASP.NET MVC?
Thanks!
P.S. Maybe there's a third-party tool for the purpose?
EDIT
Ok. The thing is not about MVC architecture! Do look here: http://jsfiddle.net/challenger/8qn22/109/
I want the master page/layout to stay when user gets redirected to the other page
Want an average page to be nested inside the content division
. So if it is a form I want this form to be displayed like:
http://jsfiddle.net/challenger/XgFGb/17/
A Master Page is a nonprinting page that you can use as the template for the rest of the pages in your document. Master pages can contain text and graphic elements that will appear on all pages of a publication (i.e. headers, footers, page numbers, etc.)
A master page is an ASP.NET file with the extension . master (for example, MySite. master) with a predefined layout that can include static text, HTML elements, and server controls. The master page is identified by a special @ Master directive that replaces the @ Page directive that is used for ordinary .
To create the master pageIn Solution Explorer, right-click the name of your Web site, and then click Add New Item. Under Visual Studio installed templates, click Master Page. In the Name box, type Master1. Select the Place code in separate file check box.
Use master pages to repeat design and layout elements on multiple pages in a publication. Using master pages for these common elements gives your publication a more consistent appearance and allows you to create and update these elements in one place, rather than changing them on each publication page.
Here's what PHP standard framework/api supports:
The require("/definitions.php")
function loads class, function and constants defines from a file and outputs the content outside of PHP code to php://stdout (on a webserver this is what is sent to the browser). You might wanna use require_once
for importing dependencies (php files with definitions).
Use the PHP's open and close tags to obtain something close to templating functionality. For example a normal page would look like this:
while an included (and repeatably includable) one could look like this:
I'm not saying "don't use templating engines", just showing a clear and simple way of achieving things which PHP is purposely built for. If this is enough for you needs, I then do say "don't use templating engines for the sake of it" (btw, if you are tidy, you can easily separate logic from views, without strict and sometimes cumbersome MVC frameworks).
Off hand, I know that the Laravel framework includes the Blade templating engine. It uses a syntax very similar to Razor.
Example:
@layout('master')
@section('navigation')
@parent
<li>Nav Item 3</li>
@endsection
@section('content')
Welcome to the profile page!
@endsection
(Razor, Blade, loller skates)
In PHP, there is a very similar technique called templating. Instead of a master page, you have a template. The language itself has no built-in templating features, but there are third-party templating engines (Smarty, PHPTAL, and XTemplate, to name a few).
If you want to have "real" master pages, it is entirely possible to implement them. Just wrap you master page into a class and include() that class into your content pages.
Also Zend Framework supports a two step view, where a view template is rendered inside a layout template. I think this satisfies your need for master pages.
See following links:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With