PHP Classes

ArabTemplate: Template compiler engine that caches output

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (9 months ago) RSS 2.0 feedNot enough user ratingsTotal: 409 All time: 6,497 This week: 69Up
Version License PHP version Categories
arab-template 21GNU General Publi...5.3PHP 5, Cache, Templates, Code Generation
Description 

Author

This class implements a template compiler engine that caches output.

It can process template file and compile them into PHP scripts.

The templates may include assigned variables, iterate over array variabled, have conditional sections, custom PHP code, include additional template files, etc..

The class executes the compiled templates and can cache the output results in local files to prevent processing the same template again.

Picture of mohamedhelal
Name: mohamedhelal <contact>
Classes: 1 package by
Country: Egypt Egypt
Age: 36
All time rank: 352339 in Egypt Egypt
Week rank: 192 Up4 in Egypt Egypt Up

Documentation

??? ???? ?????? ??????

?????? ????? ????? ???? ??????? ???? ????? ?????? ?????? ?????? 10 ?? ????? ??????? ?? ????? ? ??????? ?? ???? ?? ???? ???????? ???? ?????? ??????? ???? ???? ???

??? ????

???? ??????? ?????? ???? ????? composer

composer require mohamedhelal/arabtemplate

// ????? ???? ?? ??????

$artpl = new \ArTemplate\ArTemplate([
    // ????? ???? ???????
    'template' => realpath('path'),
    // ???? ??????? ???????
    'compiler' => realpath('path'),
    // ????? ?????? ?????
    'caching'         => false,
    // ???? ????? ?????
    'cache'    => realpath('path')
]);

  • ??????? ???????
$artpl->display('index');

// or

echo $artpl->fetch('index');
  • ????? ????????? ??????
$artpl->assign('obj', 'MyTest' );
$artpl->with('obj', 'MyTest' );

??????? ????????? ???? ??????

{{ $var }}

??????? ????????? ???? ??????

{{ $row.key }}
{{ $row[key] }}
{{ $row[$key.name] }}

??????? ???????? ???? ??????

{{ $obj->property }}
{{ MyClass::$property }}
{{ MyClass::$property.key.name }}
{{ $obj::$property }}
{{ $obj::$property.key.name }}

??????? ?????? ?? ??????

{{ myName($row,'mohamed') }}
{{ $obj->method('name') }}
{{ MyClass::method('name') }}
{{ $obj::method('name') }}
  • ??????? ?????? ???? ??????

???? ??? ??????

class MyTest
{
    public static $Myname = "Mohamedhelal";
    public static $array  = array('names' => array('first' => 'Mohamed'));
    public static function setMyName($val)
    {
        self::$Myname = $val;
        return new self();
    }
    public function getThis()
    {
        return $this;
    }
    public function getName()
    {
        return self::$Myname;
    }
}

????? ??????

{{ $obj::setMyName('Mohamed')->getThis()->getThis()->getThis()->getThis()->getName() }}

??

{{ MyTest::setMyName('Mohamed')->getThis()->getThis()->getThis()->getThis()->getName() }}

  • ??????? ????? ???? ??????
{{ include file="index" }}


{{ include 'index'  }}
{{ include $var  }}

??????? ??????? ?? ?????? ?????????

$artpl->setModuleDir('test', dirname(__FILE__).'/modules/test/views/');
$artpl->setModuleDir('users', dirname(__FILE__).'/modules/users/views/');

??? ???? ?? ???? ???????

$artpl->display('test::index');
$artpl->display('users::index');

?? ??????? ???? ???? ?????? ?? ???????


{{ include file="test::index" }}
{{ include $var }}

????? ????????? ?? ??????

{{ $name = 'mohamed helal' }}
{{ $i = 2 }}
{{ ++$i }}
{{ --$i }}
{{ $i *= 2 }}
{{ assign('my','value') }}
{{ with('my','value') }}

??????? ???? ???? ??? ?? ??????


$artpl->setFunction('ReturnArray', 'MyTest::getMyName');
{{ ReturnArray($rows) }}
{{ $myfunc = ReturnArray($rows) }}

??????? ?????? ???? ?????? ? ?? ??? ???????


{{ |function_name($var,...)| }}

????? ???? ???? ??????


 
        {{ function createMenuMapList($row,$mylinks) }}
        	{{ $row->name }} || {{ $mylinks }}
        {{ /function }}
        

??????? ?????? ???? ?? ??????? ???? ??????

{{ createMenuMapList($row,$mylinks) }}

	

??????? ???? foreach

{{ foreach $rows as $row }}
	{{ $row@key }}
   {{ foreachelse}{
{{ /foreach }}

{{ foreach $rows as $key => $val }}
   {{ foreachelse }}
{{ /foreach }}

??? ????? ??? key => val


{{ foreach $rows as $key => $val }}
   {{ foreachelse }}
{{ /foreach }}

??????? ????? ??????


{{ foreach $rows as $row }}
   {{ $row@index }}
   {{ $row@first }}
   {{ $row@last }}
   {{ $row@first }}
   
   {{ $rows@count() }}
   
   {{ $row@is_div_by(2) }}
   
   {{ $row@is_even_by(2) }}
   
{{ /foreach }}

??????? for

	{{ for $i = 0;$i < 10;$i++ }}
		{{ $i }}
	{{ /for }}

??????? for ??????

	{{ for $i = 0,$j = 0;$i < 10,$j < 10;$i++,$j+=2 }}
		{{ $i }}
		{{ $j }}
	{{ /for }}

??????? break|continue

{{ break|continue }}

??????? ?????? ???? ??????

{{ if $name =="mohamed" }}
// do same thing
{{ elseif $name =="helal" }}
// do same thing
{{ else }}
// do same thing
{{ /if }}

??????? ?????? ???????

{{ $var == 'mohamed'?true:false }}

??? ?????????

{{ $var ."MohamedHelal" }}

?????????

{{*
	// ???????  ?? ??? ???????
	{{ $var }}
*}}

??? ????? ??????

parent.tpl

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>{{ block 'header' }}My Default Page  Title {{ /block }}</title>
</head>
<body>
	{{ block 'body' }}
		My Default Page  Content
	{{ /block }}
</body>
</html>

son.tpl


{{ extends file="parent" }}
{{ extends "parent" }}
{{ extends $layout }}

{{ block "header" }}
	My Extend Page Header
{{ /block }}


{{ block "body" }}
	My Extend Page Content
{{ /block }}

??????

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>
	My Extend Page Header
</title>
</head>
<body>
	
	My Extend Page Content

</body>
</html>

  Files folder image Files (26)  
File Role Description
Files folder imageArTemplate (8 files, 1 directory)
Files folder imagecaches (2 files)
Files folder imagecompilers (4 files)
Files folder imagetemplates (7 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file index.php Example index page
Accessible without login Plain text file README.md Doc. Examples

  Files folder image Files (26)  /  ArTemplate  
File Role Description
Files folder imageplugins (2 files)
  Plain text file ArTemplate.php Class Class source
  Plain text file BaseTemplate.php Class Class source
  Plain text file DataTemplate.php Class Class source
  Plain text file FileTemplate.php Class Class source
  Plain text file TemplateCache.php Class Class source
  Plain text file TemplateCompiler.php Class Class source
  Plain text file TemplateException.php Class Class source
  Plain text file Variables.php Class Class source

  Files folder image Files (26)  /  ArTemplate  /  plugins  
File Role Description
  Accessible without login Plain text file function.myname.php Aux. Auxiliary script
  Accessible without login Plain text file functions.php Aux. Auxiliary script

  Files folder image Files (26)  /  caches  
File Role Description
  Accessible without login Plain text file 83d9f69d185c7f7b0f...ache.layout-tpl.php Aux. Auxiliary script
  Accessible without login Plain text file 93fb097ab082b4618a...cache.index-tpl.php Aux. Auxiliary script

  Files folder image Files (26)  /  compilers  
File Role Description
  Accessible without login Plain text file 83d9f69d185c7f7b0f...file.layout-tpl.php Example Example script
  Accessible without login Plain text file 93fb097ab082b4618a....file.index-tpl.php Example Example script
  Accessible without login Plain text file ad76e1deca5c45add0...ile.layout3-tpl.php Example Example script
  Accessible without login Plain text file eb38662a4a3d7ce50e...ile.layout2-tpl.php Example Example script

  Files folder image Files (26)  /  templates  
File Role Description
  Accessible without login Plain text file footer.tpl Data tpl
  Accessible without login Plain text file header.tpl Data tpl
  Accessible without login Plain text file index.tpl Data tpl
  Accessible without login Plain text file layout.tpl Data Auxiliary data
  Accessible without login Plain text file layout2.tpl Data Auxiliary data
  Accessible without login Plain text file layout3.tpl Data Auxiliary data
  Accessible without login Plain text file main.tpl Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:409
This week:0
All time:6,497
This week:69Up