2017 © Pedro Peláez
 

library view

Simple template engine

image

webunion/view

Simple template engine

  • Sunday, February 4, 2018
  • by webunion
  • Repository
  • 1 Watchers
  • 1 Stars
  • 78 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 7 % Grown

The README.md

View

Simple and Lightweight Tempate Class., (*1)

Examples:

Note that the defaul.php layout and page should exist, because the default layout and page are loaded automatically, but you can set it as a __construct parameter or using the loadLayout and loadPage methods. The default file extension is .php., (*2)

Folder Structure:
path
└───views
    ├───layouts     
    │   default.php
    │   empty.php
    │   ...
    │
    ├───pages
    │   │   default.php
    │   │   home.php
    │   │   ...
    │   └───partials
    │       partial.php
    │       ...

/path/views/layouts/default.php, (*3)

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>{#PAGE_TITLE#}</title>
        <link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>
    <h1>Hello, world!</h1>
    <?php echo $appPage;?>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="http://getbootstrap.com/dist/js/bootstrap.min.js"></script>
  </body>
</html>

/path/views/pages/home.php, (*4)

    <?php echo $someVar;?>
    <ul>
    <? foreach($last AS $v):?>
        <li><?= $v;?></li>
    <?php endforeach;?>
    </ul>

/path/views/pages/partials/partial.php, (*5)

    <aside>
    <?php echo $someVar;?>
    </aside>>

controller.php ``` php use Webunion\View; //The default layout and page are loaded automatically, but you can pass it as a parameter or using LoadLayout and LoadPage methods $view = new View('path/views/'); $view->addFixData('PAGE_TITLE', 'Some Title Page'); $view->addData('someVar', 'Some Value'); $view->addData('anotherVar', array('a', 'b', 'c')); $view->loadPartial('partialName', 'partials/partial');, (*6)

echo $view->render('home', array('last'=>'Last value')); ```, (*7)

The Versions

04/02 2018

dev-master

9999999-dev

Simple template engine

  Sources   Download

MIT BSD Style

The Requires

  • php >=5.3.0

 

The Development Requires

by Ricardo Fontanelli

view template engine