makframework/template

PHP 引擎模板

v0.1.0 2017-05-13 16:14 UTC

This package is not auto-updated.

Last update: 2024-09-29 02:13:33 UTC


README

PHP 模板引擎

这是一个以 Twig 为基础的模板引擎。

要求

  • PHP 版本 7.1 或更高
  • Composer

安装

$ composer require makframework/template

使用

创建一个包含以下代码的 index.php 文件

<?php 
require 'vendor/autoload.php';

$tpl = new Template('./templates/');
$tpl->registerLanguages(['es' => './languages/es.ini']);

$tpl->setData('user_id', 10);

echo $tpl->render('home.html', ['title' => 'home', 'products' => ['PC','Mobile']]);

如果您想翻译任何单词,创建一个包含以下代码的 ".ini" 文件

Some to translate = Algo para traducir

创建一个包含以下代码的 ".html" 文件

<html>
    <head>
        <title>{{title}}</title>
    </head>
    <body>
        <p>User ID: {{user_id}}</p>
        <ul>
         {% for product in products %}
            <li>{{producto}}</li>
         {% endfor %}
        </ul>
        
        <!-- translation -->
        <p>{{'Some to translate'|translate}}</p>
    </body>
</html>

输出

<html>
    <head>
        <title>home</title>
    </head>
    <body>
        <p>User ID: 10</p>
        <ul>
            <li>PC</li>
            <li>Mobile</li>
        </ul>
        
        <!-- translation -->
        <p>Algo para traducir</p>
    </body>
</html>

作者

许可协议

Makframework\Template 在 MIT 许可协议 下发布。

项目包含其他第三方库,这些库可能包含自己的许可协议