PHP code example of mohamedhelal / arabtemplate

1. Go to this page and download the library: Download mohamedhelal/arabtemplate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mohamedhelal / arabtemplate example snippets


$artpl = new \ArTemplate\ArTemplate([
    // اضافة مجلد القوالب
    'template' => realpath('path'),
    // مجلد الملفات المحولة
    'compiler' => realpath('path'),
    // تفعيل وإلغاء الكاش
    'caching'         => false,
    // مجلد ملفات الكاش
    'cache'    => realpath('path')
]);

$artpl->display('index');

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() }}


{{ {{ clude $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');



{{ 

{{ $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 $rows as $row }}
	{{ $row@key }}
   {{ foreachelse}{
{{ /foreach }}

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


{{ 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 $i = 0;$i < 10;$i++ }}
		{{ $i }}
	{{ /for }}

	{{ for $i = 0,$j = 0;$i < 10,$j < 10;$i++,$j+=2 }}
		{{ $i }}
		{{ $j }}
	{{ /for }}
 
{{ 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 }}
*}}

<!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>



{{ 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>