minii-php/minii

Minii,一个简单的PHP模板引擎!

1.0.0 2018-01-25 13:55 UTC

This package is not auto-updated.

Last update: 2024-09-21 02:58:12 UTC


README

Minii,是一个简单的PHP模板引擎!

安装

您可以使用 Composer 来安装它。

composer require minii-php/minii

配置

首先,您需要创建配置文件。

$config = [

    'views' => 'app/views',
    'includes' => 'app/views/components',
    'globals' => [
        'root' => 'https://:8000/'
    ]
];
  • views : 视图的位置。
  • includes : 包含的位置。
  • globals : 全局变量。

使用

// $... = new Minii\View( [ Config ] );
$minii = new Minii\View($config);

// $...->render( View , [ Variables ] );
echo $minii->render('home',['name'=>'Minii']);

渲染

Minii 使用HTML文件。

加载包含文件

您可以在视图中加载包含文件。

app/views/components/header.html

// $...->load( Include , [ Variables ] );
$header = $minii->load('header',['name'=>'Minii']);

分隔符

  • {{ $... }} : 用于打印变量。
  • {% ... %} : 用于包含组件。

app/views/home.html

{% header %}

<a href="{{ $root }}">
    <h1>{{ $name }}</h1>
</a>

{% footer %}

您可以在包含文件中使用变量。

app/views/components/header.html

// header include

<header>
    <a href="{{ $root }}">
        <span>{{ $name }}</span>
    </a>
<header>

控制结构

条件语句

您可以使用 @if@elif@else@endif 指令构建条件语句。

@if( $num == 1 )

    $num is equal to 1

@elif( $num > 1)

    $num is greater than 1

@else

    $num is less than 1

@endif

循环

@for ($i = 0; $i < 10; $i++)

    The current value is {{ $i }}

@endfor