2017 © Pedro Peláez
 

library scenic-view

Fast and simple view inheritance and templating.

image

crhayes/scenic-view

Fast and simple view inheritance and templating.

  • Friday, May 10, 2013
  • by crhayes
  • Repository
  • 2 Watchers
  • 5 Stars
  • 36 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Scenic View

Scenic View is a tiny library that provides view and template inheritance. The syntax is straight PHP but is very clean and expressive., (*1)

The following examples use PHP short syntax (to provide cleaner views) which is fine if you have control over your own server. NOTE: you should definitely use <?php ?> if you are planning to distribute your code or do not have admin access to your server., (*2)

Loading and Rendering a View

$view = new Scenic\View('path/to/views');

echo $view->render('index.php', array('title' => 'Welcome', 'name' => 'Chris'));

View Inheritance and Templating

Layouts

Create a layout (template) file that other files will extend. The $show() method displays a section of content that's defined by a child view extending it., (*3)

<html>
<head>
  <title><?= $title ?></title>
</head>
<body>
  <? $show('content') ?>
</body>
</html>

Views

Create your view that extends the layout and provides the content for the section., (*4)

 $extends('template.php') ?>

 $section('content') ?>


Welcome, = $name ?>

$end() ?>

Extending Parent's Content

What if you want to provide content in the parent, but extend that in the child? You can!, (*5)

Define a section in the template., (*6)

<html>
<head>
  <title><?= $title ?></title>
</head>
<body>
  <? $section('content') ?>
    <h1>Welcome, <?= $name ?></h1>
  <? $end() ?>
</body>
</html>

Use the @parent key in the view to specify where you want the parent content to appear., (*7)

 $extends('template.php') ?>

 $section('content') ?>
  @parent


We hope you have a great stay!, (*8)

$end() ?>

or, (*9)

 $extends('template.php') ?>

 $section('content') ?>


We hope you have a great stay!, (*10)

@parent $end() ?>

Partials

Including partial views, like headers or footers, is easy as well., (*11)

<html>
<head>
  <title><?= $title ?></title>
</head>
<body>
  <? $section('content') ?>
    <h1>Welcome, <?= $name ?></h1>
  <? $end() ?>

  <? $include('footer.php') ?>
</body>
</html>

The Versions

10/05 2013

dev-master

9999999-dev

Fast and simple view inheritance and templating.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

templating template view view inheritance