Download the PHP package maurice2k/zenplate without Composer

On this page you can find all versions of the php package maurice2k/zenplate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package zenplate

Zenplate

A small, fast PHP template engine — meant for things like emails, simple config files, and one-shot text rendering. Templates compile to plain PHP, which is then evaluated with the assigned variables in scope.

Install

Requires PHP ^8.1.

Quick start

Assign many variables at once with an associative array:

Variables

Variables start with %. They're wrapped in the configured delimiters (default { / }).

Simple

Dot access (nested arrays / objects)

Dot access nests arbitrarily deep — missing keys at any level render as the empty string, no warnings:

Bracket access

Mixed dot + bracket

Empty / falsy values

Variables are rendered through PHP's empty(). That means all of these render as the empty string:

Value Output
null ''
'' ''
0 (int) ''
'0' (str) ''
false ''
[] ''

This is intentional historical behavior — handy for templates that print a default for "missing-ish" values, surprising if you actually wanted to print 0. If you need 0 to render, pass '0 ' or convert upstream.

Conditionals

elseif chains and else clauses work as expected:

else is optional:

Operators

Allowed inside {if ...}:

A single = in a comparison context is treated as == but reported as an error (so the template still compiles to something sensible while the typo is surfaced via Compiler::getErrors()).

Functions inside if

Only an explicit whitelist is callable from inside an if condition:

Extend the list per Compiler instance:

Note: Runner::run() constructs its own internal Compiler, so to use custom functions or delimiters with the high-level API you'll currently need to compile separately and use Runner::runCompiled() (see below).

Custom delimiters

Compile once, run many

Compilation is regex-driven and not free; if you render the same template repeatedly, compile it once and feed the cached PHP into runCompiled():

runCompiled() rejects input that doesn't carry the Zenplate header so a random PHP file can't be smuggled through.

Error handling

Runner::run() throws ExecuteException on either compile errors or runtime PHP errors:

For finer-grained inspection, drive the compiler directly:

Compiler::ERROR_* constants identify each error kind (ERROR_IF_NO_ENDIF, ERROR_IF_SINGLE_EQUAL_SIGN, etc.).

Safety notes

The compiler emits PHP source that gets eval()ed by Runner::run(), so injection prevention is critical. Current defenses:

The injection probes in tests/SecurityProbeTest.php exercise the known attack surface.

Note on string literals: double-quoted strings used as array keys or in if-conditions are decoded with C-style escape rules (\n → newline, \\ → \, \" → ", etc.) at compile time, then re-emitted safely. Your template's {%foo["a\"b"]} still resolves to the array key a"b. Single-quoted strings retain PHP's stricter escape rules (only \\ and \' are special).

Even with these defenses in place, treat compiled templates as code: don't compile attacker-controlled template source unless you've threat-modelled what they could read from the eval scope ($this->vars, in particular).

Limitations

Testing

Test infrastructure (Dockerfile, compose file, phpunit config, fixtures, test cases) lives under tests/. Everything runs in Docker so there's nothing to install on the host. A Makefile at the repo root wraps the common commands:

If you'd rather not use Make, the equivalent docker compose invocation is:

CI runs the same image across PHP 8.1 / 8.2 / 8.3 / 8.4 / 8.5 on every push and PR (see .github/workflows/ci.yml).

License

LGPL-3.0. See lgpl-3.0.txt.


All versions of zenplate with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package maurice2k/zenplate contains the following files

Loading the files please wait ...