Download the PHP package haidarvm/simple-php-template without Composer

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

Simple Template Engine

A simple and lightweight PHP templating engine using pure PHP syntax. Simple Template Engine adds on to PHP's templating capabilities by introducing blocks and template inheritance.

It's easy to learn and is useful for small websites or in conjunction with microframeworks.

Requires PHP version 5.3+

Setup

To use the template engine, include loader.php, create an Environment object, and render away! The Environment's render() function takes the path to a template, renders it and returns its contents as a string.

You can also pass in an extension that will be appended to all template paths in Environment.

You can pass variables to your template via an array:

You can then access the variable $fruit in your template, and its value will be apple.

The Environment can hold variables shared by all your templates such as helpers. Set variables like this:

Now, in your template, you can use your Helper object and your colour variable.

Blocks

Blocks are sections of layout that you can define and then use later. You can define blocks by enclosing text in $this->block('name here') and $this->endblock():

This will create a Block object that you can access later through $this by using their name. For example, to output the block defined above:

You can also use if structures to set a default block to use if a block is not defined:

Output Escaping

You can escape blocks of output easily:

The function endblock returns a Block object that you can output. This is useful for escaping a Block immediately after ending it by calling escape():

As you can see above, we didn't assign a name to our block because we output it right away, and have no need to save it. If you don't assign a name to your block, it cannot be accessed later.

Filters

You can pass a closure to endblock that you want to apply to the content.

The above code converts a block's content to uppercase.

Template Inheritance

Blocks are useful because we can define blocks in one template, then extend another one and use it there! This allows us to reuse a template such as a layout multiple times with different blocks. Extending a template is done using the extend function:

When you extend a parent template, any non-block code in the child will become a special block named content in the parent. In the above code, we defined a title block and some content. Now we can use it in our extended layout. In layout.php, we can output our content and title with $this['content'] and $this['title'].

Please be careful not to name a block content unless you are intentionally defining a content block. If you define a content block, it will be prepended to the non-block content in the layout.

A template that extends a template that extends a template: If the parent template is extending another template, then any non-block content in the parent will be appended to the content block of their child. This new content block will become the content block of the grandparent.

Templates

Templates can also be created without having to render from file and their blocks can be defined within PHP. You can create a new template object through the template() function of Environment.

Remember that a Template object created this way must have a layout otherwise nothing will be rendered.

That's all!

Now you have everything you need to create a great website!


All versions of simple-php-template with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
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 haidarvm/simple-php-template contains the following files

Loading the files please wait ...