par274/templater

简单PHP应用的一个简单模板引擎。

V1 2023-01-18 23:18 UTC

This package is not auto-updated.

Last update: 2024-09-26 07:26:38 UTC


README

php license

PHP Simple Templater

简单PHP应用的一个简单模板引擎。

安装

需求 & 设置

  • Composer
  • PHP 7.4+
composer require par274/templater

或者

git clone https://github.com/par274/simple-templater
composer update

使用

<?php
use Templater\Templater;
?>

打印 DocType

<?php echo $this->getDoctype(); ?>

全局变量定义

<?php
$templater->addGlobals([
  'test' => [
      'status' => 'ok'
  ]
]);
?>
<?php echo $test->status; ?>

更改页面标题

<?php $this->setPageTitle('Depremler Tablo'); ?>

变量定义

<?php
$data = [
  'test' => 'test'
];
echo $templater->render('{page_container:index}', $data);
?>

视图/view.index.php

<?php echo $test; ?>

设置头部项

这是您可以轻松定义样式和js定义的函数。

<head>
<?php
echo $this->setHead([
    'title' => [
        'content' => $this->getPageTitle()
    ],
    '{meta_0}' => [
        'attributes' => [
            'http-equiv' => 'Content-Type',
            'content' => 'text/html; charset=utf-8'
        ]
    ],
    '{meta_1}' => [
        'attributes' => [
            'http-equiv' => 'X-UA-Compatible',
            'content' => 'IE=Edge'
        ]
    ],
    '{meta_2}' => [
        'attributes' => [
            'name' => 'viewport',
            'content' => 'user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1'
        ]
    ],
    '{link_0}' => [
        'attributes' => [
            'rel' => 'stylesheet',
            'href' => "public/vendor/vendor.css?v=1673363766"
        ]
    ],
    '{link_1}' => [
        'attributes' => [
            'rel' => 'stylesheet',
            'href' => "public/style.css?v=" . time()
        ]
    ]
]);
?>
</head>

最后查看

<?php

define('APPLICATION_SELF', __DIR__);

require(APPLICATION_SELF . '/vendor/autoload.php');

use Templater\Templater;

$templater = new Templater();
$templater->setPath(APPLICATION_SELF . '/View');
$templater->addGlobals([
    'test' => [
        'status' => 'ok'
    ]
]);

$data = [];
echo $templater->render('{page_container:index}', $data);
?>

用于此库的包

许可证

本库的许可证为MIT(MIT许可证)。它不能出售,但您可以使用它。

您可以通过此文件了解更多信息。