Style
1.0.0
由穆罕默德·納比爾(Mohamed Nabil)(https://github.com/phpmohamednabil/)!
[樣式]是輕巧的PHP模板引擎,您可以用於小型項目或教育用途。
使用簡單且靈活的用法和少量代碼,在代碼中感受大型庫中的模板引擎的功能。
安裝作曲家https://github.com/composer/composer
在您的應用程序文件夾中創建一個composer.json:
composer require php-mohamed-nabil/style
通過將其傳遞給視圖文件所在的文件夾和一個緩存文件夾來創建樣式實例。通過調用渲染方法來渲染模板。
use Style Style ;
$ style = new Style ( ' template/ ' , ' template/temp/ ' );
$ style -> render ( ' page_sections ' ,[]);您還可以使用addTempRole()函數添加自定義表達式:
$ style -> addTempRole ( ' test ' , ' ~ob ' , function ( $ capt ){
return $ capt [ 0 ]. ' ppppppppppppppppppoboobobo ' ;
});
$ style -> render ( ' page_sections ' ,[]);這使您可以在模板中使用以下內容:
here the ppppppppp : ~ob
您還可以使用擴展視圖並使用@spread(parent_view_name)
@spread('layout')另請使用@sections @AdDsection將數據從孩子發送到父級視圖
<!DOCTYPE html >
< html >
< head >
< meta charset =" utf-8 " >
< meta name =" viewport " content =" width=device-width, initial-scale=1 " >
< title > layout page </ title >
</ head >
< body >
< p class =" yield " >
<!-- this will yield data and print it here form child view -->
@addsection('content')
</ p >
</ html > @spread('layout')
<!-- add data to the main view and render show it -->
@section('content')
My first paragraph in parent view
@endsection現在,您可以將數據從一個視圖發送到另一種視圖,因為它將被編譯和硬編碼示例:
@hardcompile(test[] within h1:title data:"echo mt_rand(1,1000)")結果test.stl.php
<!DOCTYPE html >
< html >
< head >
< meta charset =" utf-8 " >
< meta name =" viewport " content =" width=device-width, initial-scale=1 " >
< title > Test </ title >
</ head >
< body >
< h1 class =" title " >
681 <!-- this a random number hardcoded by main view -->
</ h1 >
您可以這樣將數據發送到其他視圖:
@hardcompile(test['name'= > $name,$title] before h1:title data:"echo mt_rand(1,1000)")獲取查看頁面中包含的其他視圖
@display('main',['data'= > $data])在tempaltes中
< div class ="" >
@foreach($users as $user)
{$user- > username}
@endforeach
</ div > 您現在可以使用其輸入數據創建表單
[php]
print Style Style:: form ( ' / ' ,[
' method ' => ' post ' ,
' enctype ' => ' multipart/form-data ' ,
' id ' => ' first-form '
])-> formInput ( ' username ' ,[ ' class ' => ' form-control ' , ' type ' => ' text ' ])-> formInput ( ' password ' ,[ ' class ' => ' form-control ' , ' type ' => ' password ' ])-> formInput ( ' file ' ,[ ' class ' => ' form-input-file ' , ' type ' => ' file ' ])-> renderForm ();
[/php]將輸出:
< form action =" / " method =" post " enctype =" multipart/form-data " id =" first-form " >
< input name =" username " class =" form-control " type =" text " >
< input name =" password " class =" form-control " type =" password " >
< input name =" file " class =" form-input-file " type =" file " >
</ form >{$var_name}視圖之類的視圖您可以使用@backwithfalse,它只是將其轉換為返回false,並在無法執行的任何代碼或HTML的代碼中退出
如果您想顯示帖子內容或具有瀏覽器顯示的HTML代碼塊,則可以在不停止實體的情況下打印html代碼逃脫它的主要原因,或者有一個html代碼的塊,您可以將{@$ post@$ post@}用作explample:
< div class =" blog-post-content " >
{@$posts- > post_content@}
</ div > | 表達 | 描述 |
|---|---|
{$var} | 用於打印變量var,逃脫XSS |
{%$var%} | 打印var或任何逃脫或過濾的字符串 |
{@$var@} | 打印var或任何字符串而無需逃脫或過濾 |
{%var='name'} | 在視圖中定義一個變量: $ var ='name' |
{%func echo ucfirst($var)%} | 執行函數或迴聲,如果要迴聲,請迴聲單詞是可選的 |
[comment]ww [/comment] | 介於兩者之間的任何事情都不會遵守 |
[php] var_dump($arr); [/php] | 寫PHP代碼 |
{%if $var>0%} | 定義statment |
{%else%},{%elseif%} and {%endif%} | 定義其他或其他陳述,您可以使用Endif Statment結束陳述 |
@addsection($name) | 在佈局或父視圖中用於實現部分內容,這些內容將在以後在Child View中打印 |
@spread($name) | 在孩子視圖中擴展父觀點 |
@section($name) | 在兒童視圖中啟動該部分 |
@endsection($name) | 結束兒童視圖中的部分 |
@foeach | 啟動每個循環 |
@endforeach | 結束每個循環 |
@for() | 開始循環 |
@endfor | 結束循環 |
@while() | 在陳述時開始 |
@endwhile | 陳述時結束 |
@switch($var) | 開始開關陳述 |
@case($name) | 開關陳述內部的情況條件 |
@break | 打破陳述或循環 |
@continue | 繼續陳述或循環 |
@default | 默認條件開關陳述 |
@backwithfalse | 它只是將其轉換為返回false,並在未執行任何代碼或HTML的代碼中退出 |
@hardcompile(view_name[] before|after|within tagname:classname data:"php_code_here") | 硬編譯其他view_name和具有類名稱名稱的其他view_name和注入數據內容,這將在此實驗的每一個惡化中將數據發送到其他視圖 |
根據MIT許可發布。