Download the PHP package neoan3-apps/template without Composer

On this page you can find all versions of the php package neoan3-apps/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?
neoan3-apps/template
Rate from 1 - 5
Rated 5.00 based on 2 reviews

Informations about the package template

neoan3-apps/template

PHP template engine

Test Coverage Maintainability Build Status

As of version 2, we dropped PHP 7.4 support. You require at least PHP 8.0 or use v1.2.0 of this package.

Installation / Quick start

composer require neoan3-apps/template

Contents

Templating

neoan3-template is not a full blown template engine, but rather what a template engine should be: With modern JavaScript solutions creating a dynamic approach, neoan3-template focuses on the necessities of static rendering.

profile.html

profile.php

output

Main templating methods

embrace($string, $substitutionArray)

Replaces array-keys indicated by double curly braces with the appropriate value

embraceFromFile($fileLocation, $substitutionArray)

Reads content of a file and executes the embrace function.

Iterations (n-for)

The n-for loop evaluates as PHP's foreach and uses the same syntax (excluding the $-sign). In order to access keys, use the PHP markup (items as key => value) to emulate $items as $key => $value. Without the necessity to access keys, use the simple markup items => item.

Output:

Conditions (n-if)

You can attach the n-if attribute to any tag in order to render conditionally. Curly braces are not required and nesting follows the same rules as general rendering (meaning that you will write outer.inner to access $parameters['outer']['inner'])

n-if is type conscious and therefore evaluates strict.

true false
false == 'false' false === 'false'

Conditions work in nested context and inherit naming.

Example within n-for:

Output:

Custom functions

Unlike other template engines, neoan3-apps/template does not come with expensive additional functionality. It is our believe that most of what other template engines offer should not be included in a template engine. However, you can pass in custom closures to achieve custom transformation or similar.

Example:

Output:

You can even use substitutions like this (as used in php-i18n-translate):

Output:

Custom delimiter

There is a reason why curly braces are used: You can leverage the fact that some values are only potentially filled by the backend and addressed in the front-end if the value does not exist in your data (yet). However, there are also cases where you want to specifically avoid having your front-end framework picking up unfilled variables, or you have special parsing needs to work with various files. Therefore, you can use custom identifiers by providing your desired markup to embrace or embraceFromFile.

Example:

Output:

NOTE: If your delimiter is a tag, the engine will NOT remove the delimiter:

Output:

Custom Attributes

Under the hood, n-if and n-for are just custom attributes. You can add your own attributes and extend the engine to your needs using any callable:

OOP

So far, we have used a purely static approach. However, the "Template" methods are merely facades resulting in the initialization of the Interpreter. If you need more control over what is happening, or it better fits your situation, you are welcome to use it directly:

Tips

There are a few things that are logical, but not obvious:

Parents on loops

Due to processing in hierarchy, many internal parsing operations can cause race-conditions. Imagine the following HTML:

In this scenario, the parser would first hit the attribute n-for and add p-tags to the parent node (here div). n-for now takes control of this parent and interprets the children. As the context gets reevaluated in every loop, but the second p-tag is not iterated, the resulting output would be:

It is therefore recommended to use one distinct parent when using attribute methods:

Flat array properties

The interpreter "flattens" the given context-array in order to allow for the dot-notation. In this process generic values are added:

output:

If needed, you can use this in logic:


All versions of template with dependencies

PHP Build Version
Package Version
Requires ext-openssl Version *
ext-mbstring Version *
ext-json Version *
ext-dom Version *
ext-libxml Version *
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 neoan3-apps/template contains the following files

Loading the files please wait ....