PHP Classes
elePHPant
Icontem

ArabTemplate: Template compiler engine that caches output

Recommend this page to a friend!
  Info   View files Documentation   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2015-08-11 (1 year ago) RSS 2.0 feedNot enough user ratingsTotal: 361 All time: 6,496 This week: 889Up
Version License PHP version Categories
arab-template 8GNU 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: 28
All time rank: 341538 in Egypt Egypt
Week rank: 1479 Up22 in Egypt Egypt Up

Details

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

?????? ????? ????? ???? ??????? ???? ????? ?????? ?????? ?????? 8 ?? ????? ??????? ?? ????? ? ??????? ?? ???? ?? ???? ???????? ???? ?????? ??????? ???? ???? ???

??? ????

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

require 'arabTemplate.php';

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

$artpl = new ArabTemplate();

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

$artpl->caching = false;

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

$artpl->setTemplateDir('templates');

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

$artpl->setCompileDir('compilers');

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

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

// or

echo $artpl->fetch('index');
  • ????? ????????? ??????
$artpl->assign('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" caching}}
// ?????
{{include file="index" title="MyPageTitle" caching}}

{{include file=$filename title="MyPageTitle" caching}}

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

$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" title="MyPageTitle" caching}}
{{include file="users::index" title="MyPageTitle" caching}}

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

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

???? ??? ???? ?? php

$rows = array();
for ($i = 1 ;$i < 10;$i++)
{
	$rows[] = (object)array(
                     'first' => 'Mohamed-'.$i,
                    'last' => 'Helal - '.$i,
                    'id' => $i,
                    'image' => 'MyImage',
                    'code' =>'
                        <h1>Code Compiled {{$row_file->first}}</h1>
                        {{foreach $rows as $row}}
{{$row->first}}<br/>
{{myName(($row->first == \'mohamed\'?$row->first:\'mohamed\'),($row->last == \'helal\'?$row->first:\'helal\'))}}
{{/foreach}}',
                    'lastupdate' =>(time()-(60*60))
            );
}
$artpl->assign('rows',$rows);

??? ???? html

{{foreach $rows as $row_file}}
{{$_artpl->evalCode($row_file->first,$row_file->code,$row_file->lastupdate)}}
{{/foreach}}

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

{{$name = 'mohamed helal'}}
{{$name = getTemplateVars('name')}}
{{$i = 2}}
{{++$i}}
{{--$i}}
{{$i *= 2}}
{{assign var="my" value=" MyTest::$array.names.first"}}

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


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

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


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

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


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

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

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

????? ??? php???? ??????

{{php}}
	$var ='myCodeTest';
	echo $var ;
{{/php}}

	

??????? ???? 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>{{extend_header}}My Default Page  Title {{/extend}}</title>
</head>
<body>
	{{extend_body}}
		My Default Page  Content
	{{/extend}}
</body>
</html>

son.tpl

???? ???? ?? content ?? ???? ??? ?? ??? parent.tpl extend_body = body ?? ???? ???? ????


{{extends file="parent"}}
{{content name = "header"}}
	My Extend Page Header
{{/content}}


{{content name = "body"}}
	My Extend Page Content
{{/content}}

??????

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

</body>
</html>

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

	if($artpl->isCached('index'))
	{
		// do same thing
	}
	$artpl->display('index');

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

// ????? ???? ??? ?????? ?? ????? ???????? ? ????? ????? ????????
$artpl->setResource(function($name){
	$query = mysql_query("select from thems where style ='main' and name ='$name'");
	$row = mysql_fetch_assoc($query);
	return array('code' => $row['htmlcontent'],'lastupdate' => $row['lastupdate']);
});

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

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

// ????? ???? ??? ????? ??????? ?? ??? ????
$artpl->allow_output_file();

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

// ??????? ??? ?????  
$artpl->get_output_file();

  Files folder image Files  
File Role Description
Files folder imagetemplates (3 files)
Plain text file arabTemplate.php Class class file
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  /  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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:361
This week:0
All time:6,496
This week:889Up