Download the PHP package zareismail/compilex without Composer
On this page you can find all versions of the php package zareismail/compilex. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zareismail/compilex
More information about zareismail/compilex
Files in zareismail/compilex
Informations about the package compilex
Introduction
- Welcome
- Getting Started
Displaying Data
- Display Variables
- Multiple Variables
- Default Values
Directives
- Basic Of Directives
- Conditional Statements
- Positive Statements
- Loop
- Nested Statements
Customization
- Custom Directives
Introduction
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
You can install the compilex
via Composer by running the following command:
After installation, you can use the compiler as follows:
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:
For exmaple:
Multiple Variables
You can also display valid value of multiple variables by using the or
operator:
For exmaple:
Default Values
If a variable is missing, you can display a default value using a quoted string
:
For exmaple:
Basic Of Directives
By default, Compilex
supports essential directives. All of the Compilex
directives have the following syntax:
Where the directive
can be one of the default directives or any of the custom directives. The statement
should satisfy the directive requirements, and the expression
can be any renderable string.
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:
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:
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:
for exmaple:
Loop
Compilex also supports loop
statements with the following structure:
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:
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:
Custom Directives
If you need additional directives, you can easily define custom directives using the extend
method. Here's an example:
You can use your custom directive like this:
That's it! With these directives and examples, you should be able to harness the power of Compilex
in your PHP view compilation.