james-draper / cocoon
A simple php view renderer.
Installs: 9
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/james-draper/cocoon
Requires
- php: >=7.1
Requires (Dev)
- phpspec/phpspec: ^3.4
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2025-02-09 12:06:25 UTC
README
A simple php view renderer.
Requirements
- Composer
- PHP 7.1 or greater
Installation
To install Cocoon via composer, run the following command:
composer require james-draper/cocoon
Getting started
Here is a simple example of how to render a view, for a more detailed explanation consult the documentation.
<?php
$factory = new \Cocoon\Factory([__DIR__ . '/views'])
return $factory
->create('path/to/template')
->setVar('some_var', 123)
->setVarRaw('some_other_var', 456)
->render();
The above code snippet first creates a factory, uses the factory to creates a view, assigns variables to that view, and then renders the view. Below is what the template file might contain.
<p>var1: <?php echo $this->some_var; ?></p>
<p>var2: <?php echo $this->some_other_var; ?></p>