Recommend this page to a friend! |
Download .zip |
Info | Example | View files (17) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2023-08-21 (1 month ago) | Not yet rated by the users | Total: 39 This week: 1 | All time: 10,722 This week: 108 |
Version | License | PHP version | Categories | |||
style 1.0 | MIT/X Consortium ... | 7 | Templates, Code Generation, PHP 7 |
Description | Author mohamed-nabil Contributor | |||||||||||||
This package can process templates compiling them into PHP scripts. |
|
By Mohamed Nabil (https://github.com/PHPMohamedNabil/)!
[Style] is lightweight a tiny PHP Template Engine you can use for small projects or educational purposes.
Feel the power of the template engines of big libraries in your code with simple and flexible usage and little code.
<!--ts--> * Installation * Usage
* Custom Expressions
* Sections
* Hard Compiling
* Including View
* Foreach loop
* Html Creation
* Printing Vars
* Terminate the code
* Printing html Content
* Table of expressions
* Licence <!--te-->
Create a composer.json inside your application folder:
Create a Style instance by passing it the folder where your view files are located, and a cache folder. Render a template by calling the render method.
use Style\Style;
$style = new Style('template/','template/temp/');
$style->render('page_sections',[]);
You can also add custom expressions using the addTempRole()
function:
$style->addTempRole('test','\~ob',function($capt){
return $capt[0].' ppppppppppppppppppoboobobo';
});
$style->render('page_sections',[]);
Which allows you to use the following in your template:
here the ppppppppp : ~ob
You can also use extend views and using @spread(parent_view_name)
@spread('layout')
using also @sections @addsection to send data from child to parent view
<!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
you can now send data from one view to another one as it will be compiled and hardcoded example :
@hardcompile(test[] within h1:title data:"echo mt_rand(1,1000)")
results in 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>
you can send data to other view like this :
@hardcompile(test['name'=>$name,$title] before h1:title data:"echo mt_rand(1,1000)")
get other view included in view page
@display('main',['data'=>$data])
in tempaltes
<div class="">
@foreach($users as $user)
{$user->username}
@endforeach
</div>
you can now create form with its input data
[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]
will output:
<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}
of view like die you can use @backwithfalse it is just converted to return false and exit from code any code or html after it will not be executed
without stopping entities you can print html code witout escaping it the main reason of it if you want to show a post content or has a block of html code to be appear and effected by browser you can use {@$post@} as an expample:
<div class="blog-post-content">
{@$posts->post_content@}
</div>
| Expression | Description |
| --- | --- |
| {$var}
| for printing the variable var with escaping against xss |
| {%$var%}
| printing var or any string escaping or filtering it |
| {@$var@}
| printing var or any string without escaping it or filtering it |
| {%var='name'}
| define a variable inside the view :$var='name'|
| {%func echo ucfirst($var)%}
|execute the function or echo it echo word is optional if you want to echo the function|
| [comment]ww [/comment]
| any thing in between it will not be compilled|
| [php] var_dump($arr); [/php]
| write php code|
| {%if $var>0%}
| define if statment|
| {%else%},{%elseif%} and {%endif%}
| define else or elseif statment and you can use endif statment to end the statment|
| @addsection($name)
|used in layout or parent view to implement section content that will be printed later in child view |
| @spread($name)
| extend the parent view in the child view |
| @section($name)
| start the section in child view |
| @endsection($name)
| end the section in child view |
| @foeach
| start the for each loop |
| @endforeach
| end the for each loop |
| @for()
| start the for loop |
| @endfor
| end the for loop |
| @while()
| start while statment |
| @endwhile
| end while statment |
| @switch($var)
| start the switch statment |
| @case($name)
| case condition inside switch statment |
| @break
| break the statment or the loop |
| @continue
| continue the statment or the loop |
| @default
| default condition inside switch statment |
| @backwithfalse
| it is just converted to return false and exit from code any code or html after it will not be executed |
| @hardcompile(view_name[] before\|after\|within tagname:classname data:"php_code_here")
| hard compiling other view_name and inject data content before or after or within tagname that has a classname this will send data to other view on every exacute of this experission |
published under the MIT Licence.
Files |
File | Role | Description | ||
---|---|---|---|---|
src (6 files, 2 directories) | ||||
test (1 file, 1 directory) | ||||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Documentation |
Files | / | src |
File | Role | Description | ||
---|---|---|---|---|
Exceptions (3 files) | ||||
interfaces (1 file) | ||||
CompileSectionsTrait.php | Class | Class source | ||
CompileSpecialExperssionsTrait.php | Class | Class source | ||
helpers.php | Aux. | Auxiliary script | ||
HtmlBuliderTrait.php | Class | Class source | ||
Style.php | Class | Class source | ||
StyleEngine.php | Class | Class source |
Files | / | src | / | Exceptions |
File | Role | Description |
---|---|---|
NoAccessToDeleteCacheException.php | Class | Class source |
NoAccessToWriteException.php | Class | Class source |
ViewNotFoundException.php | Class | Class source |
Files | / | test | / | template |
File | Role | Description |
---|---|---|
lay.stl.php | Aux. | Auxiliary script |
page_sections.stl.php | Aux. | Auxiliary script |
test.stl.php | Aux. | Auxiliary script |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.