avalon/templating

Avalon 模板组件。

dev-master / 2.0.x-dev 2016-07-06 06:15 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:18:51 UTC


README

快速且简单的模板渲染。

安装

此包可以通过 composer 安装

composer require avalon/templating

引擎

有两个可用的模板引擎可供使用

PHP

基本上与 include 'myfile.php'; 相同,但返回渲染的视图而不是直接输出。

PHP 扩展

允许扩展其他视图并定义内容块。

<!-- layouts/default.phtml -->
<h1>My Layout</h1>
<?=$this->getSection('content')?>
<!-- my_view.phtml -->
<?php $this->extend('layouts/default.phtml'); ?>

<?php $this->startSection('pageTitle', 'My Page'); ?>

<?php $this->startSection('content'); ?>
View content here
<?php $this->endSection(); ?>

用法

此示例使用 PHP 扩展引擎。

use Avalon\Templating\View;
use Avalon\Templating\View\Engines\PhpExtended;

// Instantiate the engine
$engine = new PhpExtended;

// Set it as the engine for the `View` singleton to use.
View::setEngine($engine);

// Add some paths to search for views in
View::addPath('/path/to/views/directory');
View::addPath('/path/to/another/views/directory');

// Render a view
View::render('my_view.phtml');

// Variables can also be passed to views like so:
View::render('my_view.phtml', ['variableName' => 'Variable value']);