PHP code example of james-draper / cocoon
1. Go to this page and download the library: Download james-draper/cocoon library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
james-draper / cocoon example snippets
$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: echo $this->some_var;
echo $this->some_other_var;