PHPackages                             zareismail/compilex - 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. [Admin Panels](/categories/admin)
4. /
5. zareismail/compilex

ActiveLibrary[Admin Panels](/categories/admin)

zareismail/compilex
===================

A Laravel Nova tool.

v1.0.0(2y ago)25MITPHPPHP ^7.3|^8.0

Since May 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/zareismail/compilex)[ Packagist](https://packagist.org/packages/zareismail/compilex)[ RSS](/packages/zareismail-compilex/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Introduction
============

[](#introduction)

- [Welcome](#introduction)
- [Getting Started](#getting-started)

Displaying Data
===============

[](#displaying-data)

- [Display Variables](#display-variables)
- [Multiple Variables](#multiple-variables)
- [Default Values](#default-values)

Directives
==========

[](#directives)

- [Basic Of Directives](#basic-of-directives)
- [Conditional Statements](#conditional-statements)
- [Positive Statements](#positive-statements)
- [Loop](#loop)
- [Nested Statements](#nested-statements)

Customization
=============

[](#customization)

- [Custom Directives](#custom-directives)

Introduction
------------

[](#introduction-1)

Welcome to the documentation for **Compilex** - a powerful PHP view compilation package designed to streamline the process of rendering dynamic templates. With Compilex, PHP developers can effortlessly compile templates, replace variables, and handle logical statements, all within a string context. This package aims to provide a flexible and efficient solution for generating dynamic content, allowing developers to focus on crafting exceptional user experiences.

In this documentation, you will find comprehensive information, examples, and guidelines to help you understand and harness the capabilities of Compilex. Whether you are new to view compilation or seeking to enhance your existing workflows, this documentation will serve as a valuable resource to navigate through the features and unleash the full potential of Compilex.

Let's get started and embark on a journey to simplify view compilation in PHP!

Getting Started
---------------

[](#getting-started)

You can install the `compilex` via Composer by running the following command:

```
composer require zareismail/compilex
```

After installation, you can use the compiler as follows:

```
$compiler = new \Zareismail\Compilex\Compilex();

$result = $compiler->compile('complex string containing patterns', [/* Your variables */]);
```

Display Variables
-----------------

[](#display-variables)

You may display data that is passed to your Compilex patterns by wrapping the variable in curly braces. You can display the contents of the `name` variable like so:

```
Hello, {{ name }}.

```

For exmaple:

```
echo $compiler->compile('Hello, {{ name }}.', ['name' => 'COMPILEX']);
// Output: Hello, COMPILEX.

```

### Multiple Variables

[](#multiple-variables)

You can also display valid value of multiple variables by using the `or` operator:

```
Hello, {{ name or firstname or lastname }}.

```

For exmaple:

```
echo $compiler->compile('Hello, {{ name or firstname or lastname }}.', ['firstname' => 'COMPILEX']);
// Output: Hello, COMPILEX.
```

### Default Values

[](#default-values)

If a variable is missing, you can display a default value using a `quoted string`:

```
Hello, {{ name or '--' }}.

```

For exmaple:

```
echo $compiler->compile('Hello, {{ name or "--" }}.');
// Output: Hello, --.
```

Basic Of Directives
-------------------

[](#basic-of-directives)

By default, `Compilex` supports essential directives. All of the `Compilex` directives have the following syntax:

```
{% directive statement %} expression {% enddirective %}

```

Where the `directive` can be one of the default directives or any of the [custom directives](#custom-directives). The `statement` should satisfy the directive requirements, and the `expression` can be any renderable string.

### Conditional Statements

[](#conditional-statements)

The conditional statements are useful to `render` or `hide` expressions based on a condition. By default, we have two conditional statements: `if` and `unless`. You can use the `if` directive to render an enclosed expression if the condition is true, and the `unless` directive to render an enclosed expression if the condition is false.

The conditional statements follow the below structure:

```
{% if leftOperand comparator rightOperand %} expression {% endif %}

```

```
{% unless leftOperand comparator rightOperand %} expression {% endunless %}

```

In addition, the conditional statements support the following comparison operators:

- Equality Operators:`=`, `==`, `eq`, `equal`, `is`
- Inequality Operators: `>`, `gt`, `greater than`
- Partial Equality Operators: `>=`, `gte`, `greater than or equal`

You can generate other comparisons by changing the directive (`if`/`unless`). Here are some examples:

```
echo $compiler->compile('{% if a > b %} a is greater than b {% endif %}', ['a' => 1, 'b' => 2]);
// Output: a is greater than b

echo $compiler->compile('{% unless b > a %} a is greater than b {% endunless %}', ['a' => 1, 'b' => 2]);
// Output: a is greater than b

echo $compiler->compile('{% if a == b %} a is equal to b {% endif %}', ['a' => 1, 'b' => 1]);
// Output: a is equal to b

echo $compiler->compile('{% unless a == b %} a is not equal to b {% endunless %}', ['a' => 1, 'b' => 2]);
// Output: a is not equal to b
```

### Positive Statements

[](#positive-statements)

Sometimes you need to render conditional statements only if a variable has a valid value. For this situation, you can change the structure of the conditional statements as follows:

```
// to render enclosed epression for valid conditions
{% if variableName %} expression {% endif %}

```

```
// to render enclosed epression for invalid conditions
{% unless variableName %} expression {% endunless %}

```

for exmaple:

```
echo $compiler->compile('{% if a %} a has a valid value {% endif %}', ['a' => true]);
// Output: a has a valid value

echo $compiler->compile('{% unless b %} a doesn't have a valid value {% endunless %}', ['a' => false]);
// Output: a doesn't have a valid value
```

### Loop

[](#loop)

Compilex also supports `loop` statements with the following structure:

```
{% each valueName, indexName of/in variableName %} expression {% endeach %}

```

The `valueName` and `indexName` in the loop structure hold the `value` and `index` of your iterative variable. You can access the loop item and index inside the loop expression using these names. The `variableName` is the name of the attribute that holds your loop data, and `of` and `in` are static keywords of the loop structure. You can also omit passing the `index` name, in which case you can access the loop `index` using the `index` keyword.

Here are some examples:

```
echo $compiler->compile('{% each item, key of items %} index {{ key }} holds {{ item }}, {% endeach %}', ['items' => [1,2]]);
// Output: index 0 holds 1, index 1 holds 2,

echo $compiler->compile('{% each name in names %} The {{ index }} name is: \'{{ name }}\', {% endeach %}', ['names' => ['Jack', 'Joe']]);
// Output: The 0 name is: 'Jack', The 1 name is: 'Joe',
```

Nested Statements
-----------------

[](#nested-statements)

One of the great features of `Compilex` is supporting nested directives. This means you can use any of the statements inside other statements, and you can even use statements inside themselves. Here are some examples:

```
echo $compiler->compile('{% each item, key of items %} {% if key == 0 %} {{ item }} {% endif %} {% endeach %}', ['items' => [1,2]]);
// Output: 1

echo $compiler->compile('{% each numbers of groupedNumbers %} {% each number of numbers %} {{ number }}, {% endeach %} {% endeach %}', ['groupedNumbers' => [[1,2], [3,4]]]);
// Output: 1, 2, 3, 4,

echo $compiler->compile('{% if a > b %} {% if c > d %} I'm here {% endif %} {% endif %}', ['a' => 2, 'b' => 1, 'c' => 3, 'd' => 2]);
// Output: I'm here
```

Custom Directives
-----------------

[](#custom-directives)

If you need additional directives, you can easily define custom directives using the `extend` method. Here's an example:

```
$compiler->extend('any', function ($operand, $expression, $attributes = []) {
    foreach ((array) explode(',', $operand) as $attribute) {
        if ($this->hasAttribute($attribute) && $this->getAttribute($attribute)) {
            return $expression;
        }
    }
    return null;
});
```

You can use your custom directive like this:

```
echo $compiler->compile('{% any a,b %} my directive is working {% endany %}', ['a' => false, 'b' => true]);
// Output: my directive is working
```

That's it! With these directives and examples, you should be able to harness the power of `Compilex` in your PHP view compilation.

Happy coding!
=============

[](#happy-coding)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1075d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/188c6af1615930311adb86de0f0f1e9241b3306d8f7680c385caa6aa0810ca48?d=identicon)[zareismail](/maintainers/zareismail)

---

Top Contributors

[![zareismail](https://avatars.githubusercontent.com/u/23401061?v=4)](https://github.com/zareismail "zareismail (2 commits)")

---

Tags

laravelnova

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/zareismail-compilex/health.svg)

```
[![Health](https://phpackages.com/badges/zareismail-compilex/health.svg)](https://phpackages.com/packages/zareismail-compilex)
```

###  Alternatives

[benjacho/belongs-to-many-field

belongsToMany nova representation in field.

158811.4k1](/packages/benjacho-belongs-to-many-field)[pdmfc/nova-action-button

A Laravel Nova field to run actions.

37733.0k1](/packages/pdmfc-nova-action-button)[khalin/nova-link-field

A Laravel Nova Link field.

31562.2k2](/packages/khalin-nova-link-field)[ebess/nova-collapsible-sidebar

A collapsible sidebar for Laravel Nova.

32313.2k](/packages/ebess-nova-collapsible-sidebar)

PHPackages © 2026

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