Download the PHP package millancore/pesto without Composer
On this page you can find all versions of the php package millancore/pesto. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package pesto
Pesto
Modern PHP template engine that provides an intuitive and expressive way to build web application views. It offers a clean syntax using custom HTML attributes and supports advanced templating features like view composition, slots, conditional rendering, loops, and built-in security measures.
Pesto understands the context of {{ variables }}
and escapes them according to their scope to avoid
Cross-Site Scripting (XSS) issues.
Or, for greater clarity, use <template>, which will not be included in the final render.
Pesto templates support files with the .html or .php extension,
allowing you to integrate PHP code if needed.
- Installation & usage
- View Composition
- The
<template>Tag - Partials
- Slots
- Nested Views
- The
- Control Flow
- If Attribute
- Loop
- Inline
- Short Syntax
- Command Line
- Compile
- Lint
- Filters
- Chain Filters
- Filters with Arguments
- Add Filters
- Benchmarks
Installation & Usage
- PHP ^8.4
Pesto is available via Composer and is free of third-party dependencies
View Composition
Pesto makes it easy to reuse parts of your views
Template Tag
The <template> tag allows you to define php-* attributes
that will be evaluated but not the tag included in the final render.
<p php-if="$user->isAdmin()">Admin</p>--><p>Admin</p><template php-if="$user->isAdmin()">Admin</template>-->Admin
Partials & Slots
When working with views that are composed of other views, you can use partials and slots to avoid repetition.
Layout
View:
Nested Views
Pesto allows you to nest views, allowing you to reuse the same layout for multiple times in the same view.
Control Flow
Pesto provides two control flow directives: foreach and if, enough to build any kind of view.
If Attribute
The only rule importance for use php-elseif and php-else is the tag must be a sibling of the php-if tag.
php-ifphp-elseifphp-else
php-if allows you to conditionally render a block of code.
Loops
Pesto provides a simple way to loop over arrays or objects.
Inline
Pesto also allows you to use inline control flow directives.
Short Syntax
Every php-* attribute has a shorter p:* alias, both forms work everywhere
and can be mixed in the same template.
| Long form | Short form |
|---|---|
php-if |
p:if |
php-elseif |
p:elseif |
php-else |
p:else |
php-foreach |
p:foreach |
php-partial |
p:partial |
php-with |
p:with |
php-slot |
p:slot |
If an element has both forms of the same directive, the long form wins.
Since no client-side framework claims the p: prefix, it is safe to combine
with Vue, Alpine.js, or Lit bindings.
Command Line
Pesto ships with a pesto binary (installed at vendor/bin/pesto) to validate
and inspect templates without rendering them.
| Command | Description |
|---|---|
pesto compile <template_path> |
Validate and compile a template, print the result |
pesto -c <template_path> |
Shorthand for compile |
pesto lint <path> [<path>...] |
Validate template files or directories |
pesto help |
Show the help message |
Both commands read the template from stdin when no path is given (or with -).
Compile
Compiles a template and prints the resulting PHP, so you can see exactly what Pesto generates:
If the template is invalid, the errors are printed and the command exits with 1.
Lint
Validates templates without rendering them: it checks for unclosed {{ }}
expressions, orphan php-else/php-elseif directives, unprocessed directives,
and PHP syntax errors in the compiled output.
With --views <dir> the linter also verifies that every php-partial
reference exists in the templates root. Without explicit paths, it lints
the whole directory:
The exit code is 0 when all templates pass and 1 otherwise, so lint
fits directly into a CI pipeline.
Filters
Pesto provides a simple way to apply filters to variables using the pipe operator, you can define your own filters.
List of Filters
rawPrevents escaping of the variable.
String Filters
upperlowercapitalizetitletrimnl2brstrip_tagsslugjoin
Chain Filters
You can chain multiple filters together.
Filters with Arguments
To pass arguments to a filter, you can use the : operator.
Add Filters
Add filter to Pesto is very simple, you can create a class with public methods and add the AsFilter Attribute.
on Pesto factory pass the class to the filters option.
Benchmarks
Pesto includes benchmarks comparing performance against Blade and Twig across four scenarios: simple rendering, loops, conditionals, and partials.
Benchmarks are powered by PHPBench with 100 iterations, 10 revolutions, and 5 warmup iterations.
All versions of pesto with dependencies
ext-dom Version *
ext-libxml Version *