PHPackages                             lroot/simple-view - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. lroot/simple-view

ActiveLibrary[Templating &amp; Views](/categories/templating)

lroot/simple-view
=================

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

v1.0.0(9y ago)11.3kMITPHPPHP &gt;=5.3.0

Since Dec 10Pushed 9y ago1 watchersCompare

[ Source](https://github.com/lroot/SimpleView)[ Packagist](https://packagist.org/packages/lroot/simple-view)[ RSS](/packages/lroot-simple-view/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

SimpleView
==========

[](#simpleview)

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

Configuration
-------------

[](#configuration)

You can configure SimpleView to work with your directory structure:

```
// 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)

Rendering a view is simple:

```
// 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`.

Views
-----

[](#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.

```

    /* CSS content... */
    /* consider outputting this placeholder content in the head of your layout */

Example conetent lorem ipsum dolor sit amet, consectetur adipiscing elit.

    // ... mind blowing js code ...
    // consider outputting this placeholder content at the bottom of your layout

```

Placeholders
------------

[](#placeholders)

Placeholders allow you to associate content with a name that you can reference later.

```
SimpleView::placeholderSetContent('placeholder_name','placeholder content');
```

You can also "capture" placeholder content.

```
