PHP Classes
elePHPant
Icontem

File: README.md

Recommend this page to a friend!
  Classes of mohamedhelal  >  ArabTemplate  >  README.md  >  Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Examples
Class: ArabTemplate
Template compiler engine that caches output
Author: By
Last change: تم اضافة داله evalCode لتحويل محتوى النص الى قالب
تم اضافة داله evalCode لتحويل محتوى النص الى قالب
Date: 1 year ago
Size: 8,587 bytes
 

Contents

Class file image Download

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

?????? ????? ????? ???? ??????? ???? ????? ?????? ?????? ?????? 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();