Download the PHP package miladrahimi/phptemplate without Composer

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

PHPTemplate

A PHP template engine!

Overview

Modern application architectures follow user interface and logic segregation. Application logic layer provides information to display in user interface layer. Thus, the user interface (view) will be separated from logic layer (controller).

Template Engines offer structured solution to implement this segregation. Let's see!

User Interfaces are template files which include static (HTML) and dynamic parts. Dynamic parts are the places which Template Engine put information there. Controller pass information and template name to Template Engine. Template Engine returns compiled template (ultimate HTML). The controller send the result to the user.

PHPTemplate syntax is the best syntax for HTML, XML and tag based documents. It is designed smartly to be pretty while web designers design.

Installation

Using Composer (Recommended)

Read How to use composer in php projects article if you are not familiar with Composer.

Run following command in your project root directory:

Manually

You may use your own autoloader as long as it follows PSR-0 or PSR-4 standards. Just put src directory contents in your vendor directory.

Getting Started

Following example shows how to render profile.html template file.

A simple template file example:

And the profile.html template file:

Phrases

Phrases are simple variables which will be filled by Template Engine based on given data. As the example above illustrates {name} and {surname} are phrase.

Phrases will be HTML-safe by PHP native htmlspecialchars() function. If you need raw data to be inserted like HTML snippets, put ! after { character. See following example:

Flexible Templates

Phrases are used to display data in the view (template). But sometimes the data must be controlled or manipulated before displaying. Some data must not be displayed always, like "sign in" button when user is authenticated already. Some data must be repeated more than once, like posts in a blog homepage. PHPTemplate offers boolean and array tags to implement such cases.

Boolean Tags

Boolean tags are used to display content while the tag name as an element in the given data is true.

Let's extend the mentioned example:

And the profile.html file:

In web design level, boolean tags will be displayed in the browser.

Sequential Arrays

PHPTemplate HTML-like syntax for sequential arrays made using arrays so easy. Array can be implemented by tags just like booleans. The tag content will be repeated as much as array length. Just like a foreach loop in PHP, you need to define a name for current array element to use in the body. In PHPTemplate you can define this name by HTML-like value attribute.

And the singer.html template file:

Associative Arrays

Associative Arrays can be passed to template engine by its paired key/value without array container. Of course PHPTemplate still support it very well.

Associative arrays are pack of key/value elements. Just like a foreach() loop, you need to define two names, one for current key and one for current value.

In the following example, I have define album name for current key and year for current value.

And the singer.html template file:

Records

Records are associate array which you need to access its all the elements at once. Record concept is so useful in table designs. PHPTemplate let you access records as easy as a pie!

See the example and singles arrays which has some records:

And the singer.html template file:

Data types

PHPTemplate converts all data to strings or arrays.

All scalar data like strings, integers, floats, etc will be converted to string.

All objects which has __toString() method will be converted to strings.

All arrays and traversable objects will be converted to arrays.

All closures will be invoked and the returned value will be checked recursively.

If the data type is not convert-able to string or array, BadDataException will be thrown.

Functions

It's a good practice to avoid using logical directives in the view layer. However, you may still need to access your application APIs in the view layer. You can pass closures like other valid data types to the template engine. The passed closure must return a closure or a valid data type value to be processed and replaced in the phrase.

See the date element in the following example:

And the singer.html template file:

Scopes

Scopes override data with the same name of the higher level scope.

For example the singer records will overwrite name and surname in the following example:

And the singer.html template file:

Importing External Template Files

You may need to import external files.

See the following example which page.html imports head.html file.

And the page.html template file:

And the head.html template file:

Framework Integration

You can install PHPTemplate using Composer. While all of modern PHP frameworks supports Composer packages, You can use PHPTemplate in the most of popular frameworks easily.

License

PHPTemplate is created by Milad Rahimi and released under the MIT License.


All versions of phptemplate 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 miladrahimi/phptemplate contains the following files

Loading the files please wait ....