PHP code example of easyswoole / template

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

    

easyswoole / template example snippets



use EasySwoole\Template\Render;
use EasySwoole\Template\RenderInterface;

$template, ?array $data = null, ?array $options = null): ?string
    {
        return "your template is {$template} and data is ".json_encode($data);
    }

    public function onException(\Throwable $throwable, $arg): string
    {
        return $throwable->getTraceAsString();
    }
}
Render::getInstance()->getConfig()->setRender(new MyRender());

$http = new swoole_http_server("0.0.0.0", 9501);
$http->on("request", function ( $request,  $response){
    $ret = Render::getInstance()->render('index.html',['easyswoole'=>'hello']);
    $response->end($ret);
});

Render::getInstance()->attachServer($http);

$http->start();
bash
cd tests
php testServer.php -e 模板引擎名称