PHPackages                             php-mohamed-nabil/style - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. php-mohamed-nabil/style

ActiveLibrary[Templating &amp; Views](/categories/templating)

php-mohamed-nabil/style
=======================

Style is a php template engine for you can use for your mvc projects

238[1 issues](https://github.com/PHPMohamedNabil/Style/issues)2PHP

Since Jun 13Pushed 2y ago1 watchersCompare

[ Source](https://github.com/PHPMohamedNabil/Style)[ Packagist](https://packagist.org/packages/php-mohamed-nabil/style)[ RSS](/packages/php-mohamed-nabil-style/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (2)

Style
=====

[](#style)

By Mohamed Nabil ()!

\[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.

Features
--------

[](#features)

- Simple compiling tags *{$variable}*, *{#constant}*, @include(), *{%loop $data%}*, *{%if%}*, *\[* comment *\]*,, *{%func echo str\_len($string)%}*
- Very Easy template Compiling as one class called Style just loads the full template and compiling it.
- \[new feature\] (Hardcompiling Templates) to send data to other template file so that be injected into other template in every page load.
- Easy to inject a new experissions fell free to add as many as you want.
- Secure when printing variables , as its filtered html content against some xss attacks.

Table of contents
=================

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Custom Expressions](#custom-expressions)
    - [Sections](#sections)
    - [Hard Compiling](#hard-compiling-feature)
    - [Including View](#including-view)
    - [Foreach loop](#foreach-loop)
    - [Html Creation](#html-creation)
    - [Printing Vars](#printing-vars)
    - [Terminate the code](#terminate-the-code)
    - [Printing html Content](#printing-html-content)
    - [Table of expressions](#Expressions-of-statments)
- [Licence](#licence)

Installation
------------

[](#installation)

1. Install composer
2. Create a composer.json inside your application folder:

    `composer require php-mohamed-nabil/style`

Usage
-----

[](#usage)

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',[]);
```

Custom-Expressions
------------------

[](#custom-expressions)

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

```

Sections
--------

[](#sections)

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

```
>

	layout page

	@addsection('content')

```

```
@spread('layout')

@section('content')
  My first paragraph in parent view
@endsection
```

Hard-compiling-Feature
----------------------

[](#hard-compiling-feature)

you can now send data from one view to another one as it will be compiled and hardcoded example :

### in the view main you will write the below expression that when view main.stl.php page loaded or compilled

[](#in-the-view-main-you-will-write-the-below-expression-that-when-view-mainstlphp-page-loaded-or-compilled)

### The view test will be injected by random number in every main.stl.php page load within h1 tag that has class title

[](#the-view-test-will-be-injected-by-random-number-in-every-mainstlphp-page-load-within-h1-tag-that-has-class-title)

```
@hardcompile(test[] within h1:title data:"echo mt_rand(1,1000)")
```

results in test.stl.php

```
>

	Test

681

```

### hard compilling can be (before | after | within) the specified tag in other view to be injected

[](#hard-compilling-can-be-before--after--within-the-specified-tag-in-other-view-to-be-injected)

you can send data to other view like this :

```
@hardcompile(test['name'=>$name,$title] before h1:title data:"echo mt_rand(1,1000)")
```

including-view
--------------

[](#including-view)

get other view included in view page

```
@display('main',['data'=>$data])
```

foreach-loop
------------

[](#foreach-loop)

in tempaltes

```

@foreach($users as $user)
  {$user->username}
@endforeach

```

Html-Creation
-------------

[](#html-creation)

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:

```

```

### Printing-Vars

[](#printing-vars)

```
{$var_name}
```

Terminate-the-code
------------------

[](#terminate-the-code)

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

printing-html-content
---------------------

[](#printing-html-content)

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:

```

{@$posts->post_content@}

```

Expressions-of-statments:
-------------------------

[](#expressions-of-statments)

ExpressionDescription`{$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 experissionLicence
-------

[](#licence)

published under the MIT Licence.

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity26

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/f354324a72172e2cb6c2046cf1628e693bda6f2f383d6ea980a07b87cf6e68a1?d=identicon)[PHPMohamedNabil](/maintainers/PHPMohamedNabil)

---

Top Contributors

[![PHPMohamedNabil](https://avatars.githubusercontent.com/u/29188634?v=4)](https://github.com/PHPMohamedNabil "PHPMohamedNabil (59 commits)")

---

Tags

framwork-design-webhtml5phpphp-frameworkphp-libraryphp7php74php8php8-featurestemplate-engine

### Embed Badge

![Health badge](/badges/php-mohamed-nabil-style/health.svg)

```
[![Health](https://phpackages.com/badges/php-mohamed-nabil-style/health.svg)](https://phpackages.com/packages/php-mohamed-nabil-style)
```

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
