Download the PHP package djmattyg007/handlebars without Composer

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

Handlebars for PHP

Install

composer require djmattyg007/handlebars

Introduction

This is a PHP implementation of Handlebars templates that aims to match the interface of the JS implementation. It does not provide some of the niceties found in other similar PHP libraries, such as loading templates from files.

This is a fork of the Handlebars package from the Eden framework. It has been refactored to not rely on the magic provided by the Core package from Eden, and to not treat most of the classes as singletons. It also takes advantage of scalar type declarations available in PHP 7.

Basic Usage

Instantiating the Handlebars class

There are several parts to the Handlebars object. The first is the Runtime object. The Runtime is what ends up containing all helpers and partials. It is passed to Templates when they are compiled, and also the Compiler for use during compilation.

Next, we need a factory to generate Argument Parsers. This itself requires a factory to generate Argument Lists.

The Compiler has three dependencies: the Runtime, a factory to produce Tokenizers, and a factory to produce Argument Parsers. Each time a new Template is compiled, a new Tokenizer is created using the Tokernizer factory. While a template is being compiled, a new Argument Parser is created using the Argumetn Parser factory whenever a non-partial tag is found in the template.

Finally, we instanstiate the actual Handlebars object. This is the object you'll be interacting with to register helpers and partials, and to compile templates. It has three dependencies: the Runtime, the Compiler, and a factory to produce Data objects. Data objects are used to help easily navigate the context provided when rendering a Template.

It is recommended that you use a dependency injection system to handle construction of the main Handlebars object, so that the only part you need to worry about is registering your helpers and partials, and actually compiling your templates.

Alternatively, you can use a new convenience function for when you don't care about swapping out any of the components:

The newInstance() method accepts the same boolean parameter as the Runtime constructor, so you can still easily prevent the automatic addition of the default helpers.

Rendering

Registering Helpers

Registering Partials

Features

Production Ready

When your templates are ready for a production (live) environment, it is recommended that caching be used. To enable cache:

API

compile

Returns a template object containing the compiled code for the supplied template string.

Usage

Parameters

Returns an instance of MattyG\Handlebars\Template - call render() on the template object (or use it as a callable) to render it.

Example

registerHelper

Register a helper to be used within templates.

Helpers can return an instance of the SafeString class to ensure that the returned content is not escaped by the compiler.

Note that unlike the JS implementation of Handlebars, the concept of "this" is not bound to the current context inside of a helper. This is actually a freedom: it allows you to use any type of callable you wish.

Usage

Parameters

Example

registerPartial

Registers a reusable partial template for use within other templates

Usage

Parameters

Example

setCachePath

Enables caching of compiled templates.

Usage

Parameters

Example

setNamePrefix

Sets the name prefix for compiled templates. This is used to avoid conflicts when generating templates.

Usage

Parameters

Example

Contributing

All contributions are welcome. Ideally, all code contributions will come with new or updated tests :)


All versions of handlebars with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0.8
ext-mbstring 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 djmattyg007/handlebars contains the following files

Loading the files please wait ....