Download the PHP package hengeb/simplates without Composer

On this page you can find all versions of the php package hengeb/simplates. 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 simplates

simplates

Simplates as a template engine for PHP for lightweight templates with automatic escaping

basic usage

Your PHP file:

And in /path/to/your/templates/user/profile.php (or /path/to/your/templates/user/profile.tpl.php if you prefer) put:

This will be rendered like this:

The strings are escaped automatically but object methods and properties can be accessed.

You can use the raw method of a variable to access the raw data:

no escaping in text output

If, in the example above, you had saved your template as /path/to/your/templates/user/profile.txt.php (note the .txt in the file name), then no auto-escaping takes place but you can still use all the other features of template variables.

advanced auto-escaping feature

Object properties and return values will be auto-escaped as well. Variables can be arrays as well.

A more advaned example:

And in your template:

This will render like this (white space has been modified in the result):

Dates and times

and in your template now.tpl.php:

result:

The date is converted to the provided time zone (variable named _timeZone). If you do not provide a time zone, the time zone will not be changed.

Another way is to provide the timezone name in the call of the format method:

global variables

In the examples above all the variables are passed in the context of the template. If a variable is used in many places you can set a global template variable like this:

Reusing templates

You can use the extends and include methods to reuse templates:

In your template, use:

And in layout.php put:

And in partials/alert.php put:

Result:

return values

You can return values from your template content to the calling context.

For example, if you have a template for an email you might want to use your template to generate the subject and return it:

In your template mail/confirm.txt.php:

And in the calling context:

falsish values

The auto-escaping feature comes with the drawback that falsish variables cannot be checked with if ($value) or if (!empty($value)) because in PHP, objects are always truish and technically, all the template variables are object (of the TemplateVariable class).

Use the engine's check, the variable's isTrue or isEmpty methods or other means instead:

instead of:

use

the suggested means are:

built-in methods of template variables

Template variables come with some handy methods that make writing templates cleaner. Use them like this: <?=$data->json()?>

Note that methods of the actual object that is stored in the template variable are a bit harder to access if their name coincidentally matches one of the built-in methods of the template variable proxy class. You would have to use the __call method in this case: <?=$variable->__call('input', [$arguments])?>

extend the functionality

You can extend the TemplateVariable class and add your own methods. You have to extend the Engine class as well so it uses your class:

With this extended template engine, every template variable has a bold() method:

This will render like this:

Of course, you can also extend the Engine class itself to provide extra features.


All versions of simplates with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0.0
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 hengeb/simplates contains the following files

Loading the files please wait ....