PHP code example of tyam / bamboo

1. Go to this page and download the library: Download tyam/bamboo 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/ */

    

tyam / bamboo example snippets


// You must specify template base directory to the bamboo engine.
$basedirs = ['/your/template/dirs', '/come/here'];
$engine = new \tyam\bamboo\Engine($basedirs);

// Render the template with template variables. You get an output string.
$variables = ['title' => $this->getTitle(), 'content' => $this->getContent()];
$output = $engine->render('mytpl', $variables);
$respond->setOutput($output);

 /* You must escape string explicitly. */ 

content comes here...
 $renderer->

write anything...

 $renderer->wrap('common/layout') 

<html>
<body>
header...
<div class="main">
 $renderer->content(); 

 $renderer->wrap('common/layout'); 

<html>
<head>
<title> $renderer->yield('title') 

 $renderer->wrap('parent', ['title' => $title]) 

use tyam\bamboo\Engine;
use tyam\bamboo\VariableProvider;

class MyController implements VariableProvider
{
    // This is the method declared abstract in VariableProvider and providing side contents.
    public function provideVariables(string $template): array
    {
        // Here you provide side contents.
        return [
            'user' => $this->getUser(), 
            'notifications' => $this->getNotifications(), 
            'recommendations' => $this->getRecommendations()
        ];
    }

    public function action()
    {
        // Get domain result in some way.
        $result = $this->callDomain();

        // Pass $this as VariableProvider to bamboo engine.
        $engine = new Engine(self::$basedirs, $this);

        // Just bind domain result to the template.
        $output = $engine->render('my/template', ['result' => $result]);

        // Then output. Thanks to variable-pulling, the code is quite straight forward.
        $this->response->output($output);
    }
}

 /* Store Subject header in a section */ 

$variables = ['user' => $user, 'confirmationUrl' => $confirmationUrl];

// Pass an empty array for sections. 
$sections = new \ArrayObject();
$output = $engine->render('email/signup-confirm', $variables, $sections);

// Now we get Subject header and To header from sections
$mailer->setSubject($sections['Subject']);
$mailer->setTo($sections['To']);

$mailer->setBody($output);
$mailer->send();