Download the PHP package drroach/templator without Composer

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

templator

Scrutinizer Code Quality Build Status

Templator is a small, quick and powerful templating engine that's easy for anyone to pick up and use but is still as powerful as a fully fleged programming language.

With it's own built in caching system, you don't need to worry about loading times and as it is compiled down into PHP, you can add anything that it supports.

This project has moved

This project has moved to Gitlab.

Installing

Clone this repo into the project that you want to use it in then require the templator/Templator.php file. Once you've done that, add your templates to /templates with the .tpl file extension and load them into your views like so:

If your templates folder isn't in your root directory, you can set it's path using the setup.json file. Just make sure that the path that you enter ends with /.

Example Syntax

Echo

And that's all that you need!

Escaping

By default, all echos are escaped to protect you from potential XSS but you can stop this by adding |e or |escape like so:

You can also escape variables by using ! instead of |:

You can use {{{ and }}} to escape variables too. Like this:

Which will put the raw code onto your page including any HTML.

If

You can add ! to switch results

You can even use pre built PHP functions like empty()

You can use else statements too:

And ending your if is just as simple:

The spacing between the {{ and }} doesn't matter!

Foreach

Looping through arrays is really simple and follows a simple language structure.

You can also get array keys like so:

As you can see, ending your foreach loops is simple too:

You can also add else statements to your foreach loops. These sections will be ran if the variable that you try and loop over is empty. See the example below:

While

While loops are half implemented. You can increment or decrement variables like so:

But as of yet, you cannot change a variables number by more than one without using pure PHP. This is likely going to be changed in the next release.

Includes

Includes are now fully supported and all included files are also cached. Includes are going to be greatly worked on in future releases so that you can add a template file to your composer file (if you have one) and then instantly use that template in your code.

Includes work exactly as you'd expect. Whatever file you include is loaded into your code exactly where you load it. Any variables that you pass into your "parent" template are passed onto your "child" template automatically.

Including templates via composer

You can require desired templates that you or other people have made and use them straight in your template without having to move them around or worry about them at all using the include code like so:

Using composer to load in third party templates means that version control of these templates is very easy and getting updates is also super simple. Because these are just other templates, they can also be made very powerful. Another benefit of including templates this way, is that you wont have to rewrite code for seperate projects as you can just use the same html as an example.

JavaScript Templates

You can load your templates and add them to your page using JavaScript too. There are a couple of ways to go about this, you can "populate" the JavaScript using the Templator::populateJs() PHP method to then include a template later in JavaScript like so:

Or you can pass data straight into the JavaScript implementation of load like so:

For reference, Templator::populateJs() take in a key value array where the key is the variable name and the value is the data.

Raw Code

Something that makes this template engine stand out is that you can add raw code to the file

The Goal

The end goal is to create a fast and flexible template engine that can be quickly picked up by anyone. It would work best for teams of front and back end developers where the front end devs aren't completely comfortable writing PHP or JavaScript logic.


All versions of templator with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
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 drroach/templator contains the following files

Loading the files please wait ....