Download the PHP package affinity4/template without Composer

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

Template

Full-featured template engine with optional syntax which is easy to learn. Can use plain PHP also.

Features

Installation

Affinity4/Template is available via composer:

or

Syntax

Output a variables:

Set a variable:

To get an array item by key, such as $post['title']:

If statement:

Foreach loop:

NOTE: Can be @foreach also.

While loop:

For loop:

Layouts and Blocks

You can extend master layouts the same way as you would in any other template engine such as Twig or Blade.

Create a master layout with sections to be overridden in each view file:

File: views/layout/master.php

Then in you view:

File: views/home.php

Then simply render the view:

File: index.php

Usage

To render a template:

If you want to add new syntax you can use the addToken method after initializing the template engine.

You can also pass a callable as the second argument to the addToken method to use preg_replace_callback instead for the replacement.

Overriding Syntax

One thing which is quite original about Affinity4 Template is that it allows you to replace the Syntax class with your won simple class to create a template language of your own.

It easy to add all the features currently in Affinity4 Template by simply extending the Affinity4\Template\Tokenizer class and implementing the Affinity4\Template\SyntaxInterface. From there you need only add rules for variables, loops etc. and extend and block syntax. If you do not add extend or block rules that functionality will simply not be available.

Here is an example of creating a Blade style syntax of your own

You then simply use dependency injection when calling the Template Engine class

The your layout template (views/layout/master.blade) can be:

In views/home.blade...

Tests

Run tests:

Licence

(c) 2017 Luke Watts (Affinity4.ie)

This software is licensed under the MIT license. For the full copyright and license information, please view the LICENSE file that was distributed with this source code.


All versions of template with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
mikey179/vfsstream Version ^1.6
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 affinity4/template contains the following files

Loading the files please wait ....