1. Go to this page and download the library: Download nezamy/view library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nezamy / view example snippets
$view = new System\Views\View;
$view->view('home', ['content' => 'Here the content passed from Controller']);
$view = new System\Views\View([
'path' => 'views/',
'theme' => 'default/',
'layout' => 'layout/default.php',
'render' => 'default/templates/',
'cache' => 'storage/cache',
'compiler' => true,
//=========== echo Compiler
//escape only
'contentTags' => ['{{ ', ' }}'],
// escape and strip html tags
'escapedContentTags' => ['{( ', ' )}'],
//without escape
'rawTags' => ['{! ', ' !}']
]);
$view->view('home');
// pass data
$view->view('home', ['contentFromController' => 'The content passed from Controller']);
//OR
$view->view('home', [
'news' => [
[
'title' => 'Hello World',
'content' => 'Here is some content',
],
[
'title' => 'Second page',
'content' => 'Here is some content for second page',
]
]
]);
@{
//create variable outside section
$this->ViewBag('pageName', 'home page');
}@
@section('pageTitle'){{ $ViewBag['pageName'] }}@end
@section('content')
<h2>Hello it`s come from view file</h2>
<p>{{ $contentFromController }}</p>
@end
// scripts for this page only
@section('scripts')
<script>
</script>
@end
// news variable for test, you can pass variables to view
@{
$news = [
[
'title' => 'Hello World',
'content' => '<p>Here is some content</p>',
],
[
'title' => 'Second page',
'content' => '<p>Here is some content for second page</p>',
]
];
}@
@section('content')
<h2>Hello it's come from view file</h2>
foreach($news as $item):