2017 © Pedro Peláez
 

library simple-view

A single class file implementing the core features of a view system including layouts, partials and placeholders

image

lroot/simple-view

A single class file implementing the core features of a view system including layouts, partials and placeholders

  • Thursday, December 8, 2016
  • by lroot
  • Repository
  • 1 Watchers
  • 1 Stars
  • 485 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 12 % Grown

The README.md

SimpleView

A single class implementing the core features of a view system including layouts, partials, placeholders and caching., (*1)

Configuration

You can configure SimpleView to work with your directory structure:, (*2)

// Setup Configuration
SimpleView::setConfigProperties(array(
    SimpleView::CONFIG_VIEW_DIR   => YOUR_APP_PATH.'/app/views/',
    SimpleView::CONFIG_LAYOUT_DIR => YOUR_APP_PATH.'/app/views/_layouts/',
    SimpleView::CONFIG_PARTS_DIR  => YOUR_APP_PATH.'/app/views/_partials/'
));

Rendering

Rendering a view is simple:, (*3)

// Output your view script. Parameters: view script, data & layout
echo SimpleView::render('your-view-script', array('name'=>'Amanda'), 'your-layout');

You specify your view script, pass an associative array of data and indicate which layout you would like to wrap the view script in. You can access this passed in data as standard variables within the view script. For example array('name'=>'amanda') will become $view_name., (*4)

Views

View scripts are the primary template file. They contain the core layout for the view you are rendering. Within the layout you can include Partials content and define placeholder content for use within the enclosing layout., (*5)

```HTML+PHP , (*6)

$view_name)); ?>

Example conetent lorem ipsum dolor sit amet, consectetur adipiscing elit., (*7)


## Placeholders Placeholders allow you to associate content with a name that you can reference later. ```php SimpleView::placeholderSetContent('placeholder_name','placeholder content');

You can also "capture" placeholder content., (*8)

<?php SimpleView::placeholderCaptureStart('placeholder_name'); ?>
All content will be captured until we call placeholderCaptureEnd()
<?php SimpleView::placeholderCaptureEnd(); ?>

Getting placeholder content is simple., (*9)

echo SimpleView::placeholderGetContent('placeholder_name');

Naming things is hard so there is a set of common placeholder names if you wish. ```HTML+PHP , (*10)


## Partials Partials are like small, self contained view scripts. You can pass an associative array of data to partial templates too. ```php // Execute a partial script and echo its content echo SimpleView::partial('title.php',array('name'=>'Amanda'));

Partial templates are simple php files. The array of data will be available as variables within the partial template. ```HTML+PHP , (*11)

Hello =$parts_name?>


## Layouts Layouts are your "master" templates pulling together all your content. ```HTML+PHP <!DOCTYPE html> <html> <head> <?php // This content could be set from anywhere including the view script or a // partial included by the view script echo SimpleView::placeholderGetContent(SimpleView::PLACEHOLDER_HEAD_CONTENT); ?> </head> <body> <?php // This placeholder name is special. It will be populated with the contents // of your rendered layout. echo SimpleView::placeholderGetContent(SimpleView::PLACEHOLDER_TMPL_CONTENT); ?> <?php // This content could be set from anywhere as well echo SimpleView::placeholderGetContent(SimpleView::PLACEHOLDER_FOOTER_CONTENT); ?> </body> </html>

Further Documentation

SimpleView has extensive code level documentation and examples. To learn more about how SimpleView works just read through the code., (*12)

Todo

  • Add tests
  • Add example dir with functional layout, placeholders and partials
  • make specifying partial and view scripts the same (fix extension requirement for partials)
  • Show how to handle namespace use in templates

The Versions

08/12 2016

dev-master

9999999-dev

A single class file implementing the core features of a view system including layouts, partials and placeholders

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

template php renderer view

08/12 2016

v1.0.0

1.0.0.0

A single class file implementing the core features of a view system including layouts, partials and placeholders

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

template php renderer view

11/12 2015

1.0.0-RC2

1.0.0.0-RC2

A single class file implementing the core features of a view system including layouts, partials and placeholders

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

template php renderer view

11/12 2015

1.0.0-RC1

1.0.0.0-RC1

A single class file implementing the core features of a view system including layouts, partials and placeholders

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

template php renderer view