Php various MVC frameworks use the separation of pages and code, and assign variables to pages and template engines through templates. What is the principle of php template assignment?
The Code is as follows:
$ Data = array (
'Title' => 'ilsea ',
'LIST' => array (
'Hello ',
'World'
)
);
Include ('Show. php ');
// Show. php Template File
Echo $ data ['title'];
Echo'
';
Print_r ($ data ['LIST']);
?>
Define a function to include templates and pass data
The Code is as follows:
// Define a function to include the template and transmit data. It should be defined in the public function library. I will write it here directly.
Function template ($ template, $ data)
{
If (isset ($ data )){
Foreach ($ data as $ key => $ val ){
$ Key = $ val;
}
Unset ($ data );
}
Include ($ template );
}
Template ('Show. php', $ data );
Of course, this example is not a complete writing method. It is just a small example. The principle of template assignment is as follows.