Native PHP template system: Plates-php Tutorial

Source: Internet
Author: User
Native PHP template system: Plates is a native PHP template system, which is very easy to use and expand and is inspired by the Twig template engine, including modern template language functions. Plates is mainly provided for developers who choose to use native PHP templates in the compilation template language.

Here is a simple example of how to use Plates. We will assume the following directory stucture:

`-- path    `-- to        `-- templates            |-- template.php            |-- profile.php
Within your controller
// Create new Plates instance$templates = new League\Plates\Engine('/path/to/templates');// Render a templateecho $templates->render('profile', ['name' => 'Jonathan']);
The page template

Profile. php

 layout('template', ['title' => 'User Profile']) ?>User Profile

Hello, e($name)?>

The layout template

Template. php

    <?=$this->e($title)?>
 section('content')?>


Noteworthy features
  • Native PHP template, no need to learn new syntax

  • Plates is a template system, not a template language

  • Plates encourages the use of existing PHP functions

  • Improve code reuse by using template layout and inheritance

  • Cross-template data sharing

  • Built-in escape help functions

  • No fixed framework, which can be used in any project

  • Decoupling design, easy to test

  • Support for Composer, compatible with PSR-2

Project homepage:Http://www.open-open.com/lib/view/home/1431008255398

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.