2017 © Pedro Peláez
 

library view

View - Template engine for PHP

image

nezamy/view

View - Template engine for PHP

  • Sunday, June 10, 2018
  • by nezamy
  • Repository
  • 1 Watchers
  • 2 Stars
  • 17 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 31 % Grown

The README.md

View

View - Template engine for PHP, (*1)

Installation

composer require nezamy/view

Usage

require BASE_PATH.'vendor/autoload.php';
$view = new System\Views\View;
$view->view('home', ['content' => 'Here the content passed from Controller']);

Default Options

$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',
        ]
    ]    
]);

layout

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>@section('pageTitle')</title>
</head>
<body>
@section('content')

@section('scripts')
</body>
</html>

view

  • View file (views/default/home.php)
@{
    //create variable outside section
    $this->ViewBag('pageName', 'home page');
}@

@section('pageTitle'){{ $ViewBag['pageName'] }}@end

@section('content')


Hello it`s come from view file

{{ $contentFromController }}, (*2)

@end // scripts for this page only @section('scripts') @end

Views with render

// news variable for test, you can pass variables to view
@{
    $news = [
        [
            'title' => 'Hello World',
            'content' => '

Here is some content, (*3)

', ], [ 'title' => 'Second page', 'content' => '

Here is some content for second page, (*4)

', ] ]; }@ @section('content')

Hello it's come from view file

<?php foreach($news as $item):?> @render('block', ['item' => $item]) <?php endforeach;?> @end
  • Render file (views/default/templates/block.php)


{{ $item['title'] }}

{! $item['content'] !}


Disable Layout

$view = new System\Views\View;
$view->layout(false)->view('home');
// OR in view file i.e home.php
@layout('false')

Change Layout

$view = new System\Views\View;
$view->layout('layout/dashboard.php')->view('home');
// OR in view file i.e home.php
@layout('layout/dashboard.php')

The Versions

10/06 2018

dev-master

9999999-dev https://github.com/nezamy/view

View - Template engine for PHP

  Sources   Download

MIT

The Requires

 

view justframework

10/06 2018

v1.0.1

1.0.1.0 https://github.com/nezamy/view

View - Template engine for PHP

  Sources   Download

MIT

The Requires

 

view justframework

03/06 2018

v1.0

1.0.0.0 https://github.com/nezamy/view

View - Template engine for PHP

  Sources   Download

MIT

The Requires

 

view justframework