Download the PHP package rgamba/tonic without Composer

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

tonic

Build Status

Super fast and powerful template engine. Pure PHP, zero dependencies.

Usage

Using Tonic is pretty straight forward.

It's also very flexible. The above code can also be written like:

Show me the syntax

Using Tonic

vs. writting all in PHP

Installation

Install using composer

Caching

All tonic templates are compiled back to native PHP code. It's highly recommended that you use the caching functionality so that the same template doesn't need to be compiled over and over again increasing the CPU usage on server side.

Modifiers

Modifiers are functions that modify the output variable in various ways. All modifiers must be preceded by a variable and can be chained with other modifiers. Example:

We can also use modifiers in the same way when using associative arrays:

Working with dates

It's easy to handle and format dates inside a Tonic template.

And the template

Working with timezones

Which will render $my_date to the timezone configured in Tonic::$local_tz

Custom timezone

List of modifiers

Name Description
upper() Uppercase
lower() Lowercase
capitalize() Capitalize words (ucwords)
abs() Absolute value
truncate(len) Truncate and add "..." if string is larger than "len"
count() Alias to count()
length() alias to count()
date(format) Format date like date(format)
nl2br() Alias to nl2br
stripSlashes() Alias to stripSlashes()
sum(value) Sums value to the current variable
substract(value) Substracts value to the current variable
multiply(value) Multiply values
divide(value) Divide values
addSlashes() Alias of addSlashes()
encodeTags() Encode the htmls tags inside the variable
decodeTags() Decode the tags inside the variable
stripTags() Alias of strip_tags()
urldecode() Alias of urldecode()
trim() Alias of trim()
sha1() Returns the sha1() of the variable
numberFormat(decimals) Alias of number_format()
lastIndex() Returns the last array's index of the variable
lastValue() Returns the array's last element
jsonEncode() Alias of json_encode()
replace(find,replace) Alias of str_replace()
default(value) In case variable is empty, assign it value
ifEmpty(value [,else_value]) If variable is empty assign it value, else if else_value is set, set it to else_value
if(value, then_value [,else_value [,comparisson_operator]] ) Conditionally set the variable's value. All arguments can be variables
preventTagEncode() If ESCAPE_TAGS_IN_VARS = true, this prevents the variable's value to be encoded

Creating custom modifiers

If you need a custom modifier you can extend the list and create your own.

And you can easily use this modifier:

Anonymous modifiers

Sometimes you just need to call functions directly from inside the template whose return value is constantly changing and therefore it can't be linked to a static variable. Also, it's value is not dependant on any variable. In those cases you can use anonymous modifiers. To do that, you need to create a custom modifier, IGNORE the $input parameter in case you need to use other parameters.

Then you can call it directly from the template

Context awareness

Tonic prevents you from escaping variables in your app that could led to possible attacks. Each variable that's going to be displayed to the user should be carefully escaped, and it sould be done acoardingly to it's context. For example, a variable in a href attr of a link should be escaped in a different way from some variable in a javascript tag or a <h1> tag. The good news is that tonic does all this work for you.

And the HTML

Include templates

You can include a template inside another template

We can also fetch and external page and load it into our current template

Templates includes support nested calls, but beware that infinite loop can happen in including a template "A" inside "A" template.

Control structures

If / else

Making conditionals is very easy

You can use regular logic operators (==, !=, >, <, >=, <=, ||, &&) or you can use the following

Operator Equivalent
eq ==
neq !=
gt >
lt <
gte >=
lte <=

Loops

Or if the array key is needed

Working with macros

Both if structures and loop constructs can be written in a more HTML-friendly way so your code can be more readable. Here's an example:

Which is exactly the same as:

Template inheritance

Tonic supports single template inheritance. The idea behind this is to keep things nice and simple. Multiple inheritance can lead to complicated views difficult to maintain.

In Tonic, template inheritance is based on blocks. Suppose we have the following base template:

base.html

Then you have several partial templates or views and you would like to reuse the main base.html as a "skeleton". To do that, we work with blocks. Each block is defined by the tag {block name}{endblock} and/or by the html attribute tn-block="name" which effectively encloses the HTML element with the attibute as the block with the name name.

inner.html

As a result we will have the following view:

There are several keys here:

NOTE It is also possible to define blocks using the {block header}{endblock} notation. We prefer to use HTML attributes as it is cleaner. Example:

is exactly the same as:

Changelog


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

Loading the files please wait ....