Code Monkey home page Code Monkey logo

pate's Introduction

Pate

Pate is a PHP Attribute Template Engine inspired by PHPTAL but run much faster. It uses syntax like angular and vue, But renders on the server side. It's compatible with PHPTAL.

Why Use Pate Instead Of PHPTAL?

I use PHPTAL as our template engine in one of my Project. But is was TOO SLOW!!, and TOO COMPLICATED. So I decide to rewrite a similar Template Engine named PATE.

Here are some advantages:

  • TREE times faster than PHPTAL. PHPTAL takes several seconds to render a big page(abount 150k), but PATE is more than 3 times faster.
  • PATE is Extremely Extensible. PATE is designed for extensible, You can create your own Syntax to enhance PATE's feature.
  • PATE is Extremely Easy. There are only 1/10 codes of PHPTAL, but much more powerful.
  • PATE's compiled file is VERY READABLE. But PHPTAL's compiled file is complicated and very hard to read.
  • PHPTAL is too strict with dom and variables, error occurs frequently. Pate is friendly.

Requirements

To use Pate, you need

  • PHP >= 5.4.

  • With dom extension installed.

Install

With composer

composer require softwarezhu/pate

Examples

Attributes

Template file

<html>
<head>
</head>
<body>
<img tal:attributes="src data/src; alt data/title"/>
</body>
</html>

Do render(ie. This template is named 'template.html')

use Pate\PateTemplate;

$template = new PateTemplate();
$template->loadHtmlFile('template.html');
$content = $template->render(array(
    'data' => array(
        'src' => 'htttp://github.com/logo.jpg',
        'title' => 'Github Logo'
    )
));

echo $content;

The render result will be

<html>
    <head>
    </head>
    <body>
        <img src="htttp://github.com/logo.jpg" alt="Github Logo"/>
    </body>
</html>

Template Syntax

Attributes

 <img tal:attributes="src data/src; alt data/title"/>

The img src and alt attributes will be replaced by the data['src'] value and data['title'] value. The multiple attributes use ";" to separate.

Text

 <span tal:content="data/title">This content will be replaced after rendered. </span>

Loop

<tr tal:repeat="product products" tal:content="product/title">This content will be replaced by product/title after rendered. </tr>

If the count of products is N, there will be N tr lines.

If

 <div tal:condition="product/isPromote" tal:content="product/discount">If product/isPromote is false, this block will be removed from the dom. </div>

tal:condition likes if in php.

Replace

 <div tal:replace="123">This entire DIV will be replaced with '123'(not the inner text). </div>

pate's People

Contributors

softwarezhu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.