antidot-fw/phug-template-renderer

Antidot 框架 Phug 模板渲染库

0.1.0 2021-01-10 14:19 UTC

This package is auto-updated.

Last update: 2024-08-30 01:20:15 UTC


README

Scrutinizer Code Quality Code Coverage Build Status Code Intelligence Status

安装

使用 composer

composer require antidot-fw/phug-template-renderer

Antidot 框架

它将直接运行,你只需要在你的请求处理器的构造函数中注入 TemplateRenderer 接口

作为独立组件

请参阅 src/Container 中的工厂类。

配置

<?php

declare(strict_types=1);

$config = [
    'pug' => [
        'pretty' => true,
        'expressionLanguage' => 'js',
        'pugjs' => false,
        'localsJsonFile' => false,
        'cache' => 'var/cache/pug',
        'template_path' => 'templates/',
        'globals' => [],
        'filters' => [],
        'keywords' => [],
        'helpers' => [],
        'default_params' => [],
    ],
];

用法

请参阅完整的 PHP Pug 文档 以获取更多详细信息。

在请求处理器中

<?php

declare(strict_types=1);

use Antidot\Render\TemplateRenderer;
use Laminas\Diactoros\Response\HtmlResponse;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

class SomeHandler implements RequestHandlerInterface
{
    private TemplateRenderer $template;

    public function __construct(TemplateRenderer $template) 
    {
        $this->template = $template;
    }

    public function handle(ServerRequestInterface $request) : ResponseInterface
    {
        return new HtmlResponse(
            $this->template->render('index', [
                'name' => 'Koldo ;-D',
            ])
        );
    }
}
// templates/index.pug
html
    head
        title Antidot Todo List app
        link(rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css")
        link(href="//fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet")
    body
        main
            section(class="container")
                h1 Hello #{name} 

    script(type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js")
    block scripts