Download the PHP package velliz/pte without Composer
On this page you can find all versions of the php package velliz/pte. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package pte
PTE - Puko Templating Engine
PTE is a standalone templating engine built for performance and compatibility for standalone use.
When PTE is in action, it traverses an HTML DOM tree into a PHP array (lexer) and combines the output with data specifications (parser).
On average, it takes 0.004 seconds to render the HTML page with caching turned off,
and 0.002 seconds with caching turned on, based on the provided example in index.php
.
Installation
composer require velliz/pte
The command is used to install the "velliz/pte" package using Composer. It adds the package as a dependency to your project.
Another requirement:
- ext-json
- ext-xmlrpc
Tags Available
Tags | Description |
---|---|
{!x} |
Value or Part Objects tags |
<!--{!x}--> |
open loop tags |
<!--{/x}--> |
close loop tags |
{!fn()} |
function tags with no parameters |
{!fn(x)} |
function tags with one parameters |
{!fn(x,y,z)} |
function tags with multiple parameters |
{CONTENT} |
CONTENT tags only works on master file |
{!css(<link href="" rel="stylesheet" type="text/css" />)} |
CSS tags |
{!js(<script src="" type="text/javascript"></script>)} |
JavaScript tags |
{!part(css)} |
move CSS tags location to this tag |
{!part(js)} |
move JavaScript tags location to this tag |
{x.html} |
segment file tags |
Usage sample
Instance the object:
In the code snippet above, an object of the Pte class is instantiated with three parameters: true for caching the template file, true for using the master file, and true for using the HTML body file.
The master file is set using the SetMaster() method with the file path 'template/master.html', and the HTML file for the view template is set using the SetHtml() method with the file path 'template/view.html'.
You also can create your own parsing rules with custom class like this:
The above code defines the BaseUrl class, which implements the \pte\CustomRender interface. The Parse() method is used to define custom parsing rules for the templating engine. In this example, if the function name is 'url', it returns a URL constructed using the provided parameter. Otherwise, it returns an empty string.
To render tags in the HTML DOM using the BaseUrl custom class, you can use the following code:
In order to set the data value, you can create an instance of the BaseUrl class and pass it as the first parameter to the SetValue() method. The second parameter should be the data in an array format. Here's an example:
To obtain the result, you can use the Output() method, which processes the HTML input using the lexer and parser. Here's an example:
You also have the option to choose Pte::VIEW_JSON as the output format.
Examples
master.html
view.html
About
Crafted with <3 from Bandung, Indonesia.
Copyright 2017 by Didit Velliz