Masterpage Usage



In this masterpage structure, there is a masterpage in the center and the views are placed on the page designated as the masterpage. In this method, the inner page is used in the $ view variable so that it can be positioned at the desired position in the masterpage . This variable automatically represents the content of the view page that the active controller currently loads.

 

 

# Specify Masterpage


The process of determining Masterpage is described in the "Configuration" section. The name of the page you want to set as masterpage should be written in the bodyPage setting in the following file .

File: Config / Masterpage.php
Sample Masterpage Page

For example, an attempt has been made to give an idea about how the internal structure of a MasterPage should look like below.

File:  Views / masterpage.php
Import::view('sections/header');

if( isset($leftside)  ) Import::view('sections/leftside');
if( isset($rightside) ) Import::view('sections/rightside');

echo $view;

Import::view('sections/footer');

The $ view variable used above is a special variant. It represents the view automatically loaded by the active controller.

 

 

# Activating Masterpage


It is sufficient for the controllers to have at least one configuration configured to activate the masterpage. As an example, the title setting is configured below.

File: Controllers / example.php
main()
    {
        Masterpage::title('Example Main Page');
        Masterpage::meta(['name:author' => 'ZN Framework']);
        
        View::content('Example Content');
    }

    public function other()
    {
        Masterpage::title('Example Other Page');
    }
}

In the above usage, we sent data both to the page designated as masterpage and to the page itself.

General Activity

If you define at least one Masterpage setting in the startup controller, you can use it automatically for all controllers. You do not need to use a valid setting for this. The important thing is to call the masterpage.

File:  Controllers / StartingController.php
<?php namespace Project\Controllers;

class StartingController extends Controller
{
    public function main()
    {
        Masterpage::status(true);
    }
}

 

 

# Appearance Placement


The $ view variable is used to set the view of the active control to the page set as masterpage .

File:  Views / masterpage.php
Import::view('header');

echo $view; // Aktif görünüm sayfamızı yerleştirdik.

Import::view('footer');

The purpose of this process is to design the main components.