Download the PHP package swiftly/template without Composer

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

Swiftly - Template

PHP Version CircleCI Coverage Status

Manage and render PHP templates.

Designed primarily to be used for SwiftlyPHP projects but can also be used on its own, the template component provides a straightforward utility for loading PHP files and capturing any output they generate.

The library also provides several helpers to make working in mixed HTML/PHP contexts easier, including the ability to display JSON, escape HTML character entities and render sub-components.

Installation

To install the library use Composer:

Usage

Basic Templates

Using the template renderer in its most basic form only requires a few steps of setup.

To demonstrate, lets say we have a simple PHP template called hi.php that contains the following:

Normally, including a file like this would cause its content to be sent directly to the user.

To render the content and capture it in a variable we must instantiate a fresh instance of the Engine class. The Engine class has only one method render(), which we pass the name of the file we wish to load.

For our Engine to first find the templates however, we'll need to construct a FileFinder which is responsible for locating templates on the filesystem.

The variable $output now contains the string Hello world! - the templating system in it's simplist form!

Going deeper

While the above example may be trivial it shows several key concepts including how templates are found and how to render them. But what if we need to pass data into our templates?

Luckily, the render() method takes an optional second argument which allows you to do just that.

Let's say we have a template file like the following:

As we can see, this template expects 2 variables: $name and $age to exist and have values. To pass them to the template we provide an array of values to the render() method like so:

Here we can see a one-to-one mapping. The keys of the given array become the names of the variables - $name and $age respectively - and the provided values are made available inside the template.

Hopefully you can start to see where this might become useful. Providing variables to a template in this manner allows you to separate your files into dedicated areas of concern, letting you perform your logic in one place while display/markup is handled in dedicated template files.


All versions of template with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8
ext-json Version *
symfony/polyfill-php80 Version ^1.23
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 swiftly/template contains the following files

Loading the files please wait ....