koine/view

Simple View renderer

1.0 2015-08-15 23:39 UTC

This package is not auto-updated.

Last update: 2024-04-13 14:02:36 UTC


README

Simple view renderer for phtml files

Code information:

Build Status Coverage Status Code Climate Scrutinizer Code Quality

Package information:

Latest Stable Version Total Downloads Latest Unstable Version License Dependency Status

Usage

$config  = new \Koine\View\Config;

$config->addPath('/path1')
    ->addPath('/path2')
    ->addPaths(array(
        'path3',
        'path4',
    ));

$config->setHelper('escaper', new \MyEscaper());

$viewRenderer = new \Koine\View\Renderer($config);

echo $viewRenderer->render('post_template.phtml', array(
    'title'        => 'Some Title',
    'body'         => 'Some content',
    'relatedPosts' => $relatedPosts,
));

The templates:

<!-- post_template.phtml -->
<article>
    <!-- either $this->escape() or $this->getHelper('escaper')->escape() will work -->
    <h1><?= $this->escape($title) ?></h1>
    <div class="body"><?= $this->getHelper('escaper')->escape($body) ?></div>

    <?= $this->partial('related_posts.phtml', array(
            'posts' => $relatedPosts
        ));
    ?>
</article>

<!-- _related_posts.phtml -->
<sidebar class="related">
    <h2>Related Posts</h2>
    <?php foreach ($posts as $post) : ?>
        <?= $this->partial('related_post.phtml', array(
            'title' => $post['title'],
            'url'   => $post['url'],
        )) ?>
    <?php endforeach ?>
</sidebar>

<!-- _related_post.phtml -->
<a href="<?= $this->getHelper('escaper')->escape($url) ?>"><?= $this->getHelper('escaper')->escape($title) ?></a>

Installing

Via Composer

Append the lib to your requirements key in your composer.json.

{
    // composer.json
    // [..]
    require: {
        // append this line to your requirements
        "koine/view": "dev-master"
    }
}

Alternative install

Issues/Features proposals

Here is the issue tracker.

Contributing

Only TDD code will be accepted. Please follow the PSR-2 code standard.

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

How to run the tests:

phpunit --configuration tests/phpunit.xml

To check the code standard run:

phpcs --standard=PSR2 lib
phpcs --standard=PSR2 tests

Lincense

MIT

Authors