PHP 原生模板

| 选择喜欢的代码风格  

现今的 PHP 框架都会使用一些模板系统,这当中多数是使用原生的 PHP 语法。在框架之外,一些类库比如 PlatesAura.View,提供了现代化模板的常见功能,比如继承、布局、扩展,让原生的 PHP 模板更容易使用。

原生 PHP 模板的简单示例


使用Plates 类库

<?php // user_profile.php ?>

<?php $this->insert('header', ['title' => 'User Profile']) ?>

<h1>User Profile</h1>
<p>Hello, <?=$this->escape($name)?></p>

<?php $this->insert('footer'); ?>

原生 PHP 模板使用继承的示例


使用Plates 类库

<?php // template.php ?>

<html>
<head>
    <title><?=$title?></title>
</head>
<body>
<main>
    <?=$this->section('content')?>
</main>
</body>
</html>
<?php // user_profile.php ?>
<?php $this->layout('template', ['title' => 'User Profile']) ?>

<h1<User Profile</h1>
<p>Hello, <?=$this->escape($name)?></p>


发表评论