PHP code example of germania-kg / renderer

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

    

germania-kg / renderer example snippets


interface RendererInterface {
    /**
     * @param  string   $template   The template file
     * @param  array    $context    Associative template variables array
     * @return string   Template output
     */	
     public function render( $template, array $context = array()) : string
  
    /**
     * Callable alias for render()
     */	
     public function __invoke( $template, array $context = array())
}


use Germania\Renderer\PhpRenderer;

// Base path and PSR-3 Logger are optional.
// Base path defaults to PHP's getcwd()
$php = new PhpRenderer;
$php = new PhpRenderer( '/path/to/c.php', [
	'foo'  => 'bar',
	'user' => $container->get('var')
]);


// myinc.php
return $response;


use Psr\Http\Message\ResponseInterface;

$render = new PhpRenderer;

$result = $render('myinc.php', [
	'response' => new GuzzleHttp\Psr7\Response
]);

echo $result instanceOf ResponseInterface
? $result->getBody()
: $result;


use Germania\Renderer\TwigRenderer;

// Have your Twig_Environment at hand;
// Logger is optional.
$render_twig = new TwigRenderer( $twig, $logger ) ;

// Pass file name and variable context:
echo $render_twig('mytwig.tpl', [
	'foo'  => 'bar',
	'user' => $container->get('var')
]);


use Germania\Renderer\SmartyRenderer;

// Have your Smarty3 at hand;
// Logger is optional.
$render_smarty = new SmartyRenderer( $smarty ) ;
$render_smarty = new SmartyRenderer( $smarty, $logger ) ;

// Pass file name and variable context:
echo $render_smarty('mysmarty.tpl', [
	'foo'  => 'bar',
	'user' => $container->get('var')
]);


use Germania\Renderer\TwigRenderer;
use Germania\Renderer\RenderedMarkdownRenderer;
use cebe\markdown\Markdown;

// Have a RendererInterface instance at hand,
// as well as Carsten Brandt's Markdown Parser.

$twig_render = new TwigRenderer( $twig, $logger );
$markdown = new Markdown;

// Pass them to constructor:
$rendered_markdown_renderer = new RenderedMarkdownRenderer($twig_render, $markdown);

// Pass file name and variable context:
echo $rendered_markdown_renderer('twigged_markdown.md', [
	'foo'  => 'bar',
	'user' => 'Joe'
]);