Simple view renderer for phtml files
Code information:
Package information:
$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>
Append the lib to your requirements key in your composer.json.
{
// composer.json
// [..]
require: {
// append this line to your requirements
"koine/view": "dev-master"
}
}
- Learn composer. You should not be looking for an alternative install. It is worth the time. Trust me ;-)
- Follow this set of instructions
Here is the issue tracker.
Only TDD code will be accepted. Please follow the PSR-2 code standard.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
phpunit --configuration tests/phpunit.xml
phpcs --standard=PSR2 lib
phpcs --standard=PSR2 tests