Download the PHP package yakub/simple-templating without Composer
On this page you can find all versions of the php package yakub/simple-templating. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yakub/simple-templating
More information about yakub/simple-templating
Files in yakub/simple-templating
Package simple-templating
Short Description Simple templating for php
License Apache-2.0
Informations about the package simple-templating
simple-templating
Simple templating for PHP. You can replace strings and use basic PHP functions.
Build status
Install
The recommended way to install is via Composer:
Example
Simple usage
Parameters
- \$template - String template using syntax
- \$scope - Associative array
- \$flags - Additional options for replacing - USE_URLENCODE - Every replaced string will be encoded by
rawurlencode()
Syntax
Available syntax examples
String data
Scope data:
- '{{name}}' -> 'Jakub Miškech'
- '{{fn.strtoupper(name)}}' - 'JAKUB MIŠKECH'
- '{{name[0]}}' - 'J'
- '{{fn.ucwords('hello world')}}' - 'Hello World'
- '{{fn.urlencode(name)}}' - 'Jakub+Mi%C5%A1kech'
Time data
Scope data:
- '{{fn.date('Y-m-d H:i:s')}}' -> '2020-04-27 17:01:31'
- '{{fn.time()}}' -> '1580140891'
- '{{fn.strtotime(strtotimeValue)}}' -> '1579993200'
- '{{fn.strtodate('yesterday')}}' -> '2020-04-26 00:00:00'
- '{{fn.strtodate('yesterday', 'Y-m-d')}}' -> '2020-01-26'
Number data
Scope data:
- '{{fn.round(1.5)}}' -> '2'
- '{{fn.round(numberA)}}' -> '1'
- '{{fn.rand(0, 100)}}' -> '41'
Array data
Scope data:
- '{{fn.implode(', ', values)}}' -> '1, 2, 3, 4'
- '{{values[0]}}' -> '1'
- '{{fn.implode(', ', fn.array_column(statuses, 'title'))}}' -> 'PHP: Hypertext Preprocessor, PostgreSQL'
- '{{fn.explode(',', forExplode)[1]}}' -> 'hello'
- '{{statuses[0]['title']}}' -> 'PHP: Hypertext Preprocessor'
- '{{statuses[1][displayName]}}' -> 'PostgreSQL'
- '{{statuses[1][map.statusesPK]}}' -> 'pg'
Functions
All available function. More in php.net
-
Number
- round, rand, pow, floor, abs
-
Date time
- time, date, gmdate, strtotime, strtodate*
-
Array
- explode, implode, array_column, array_push, array_merge
- String
- trim, strlen, substr, strpos, strstr, sprintf, ucfirst, ucwords, strtoupper, strtolower, strip_tags, str_replace, urlencode, rawurlencode
Arithmetic operators
Arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication and division.
Scope data:
- '{{1 + 2}}' -> '3'
- '{{1 + 2 * 3}}' -> '7'
- '{{(1 + 2) * 3}}' -> '9'
- '{{(1.2 + 2,4) * float}}' -> '19.44'
- '{{fn.round((done / total)*100, 2)}} %' -> '9 %'
Conditions
Syntax allow use inline condition with using logical and comparison operators.
Scope data:
- '{{(success) ? ok : notOk)}}' -> 'ok'
- '{{(! success) ? ok : notOk)}}' -> 'not ok'
- '{{1 && (0 || success) ? ok : notOk)}}' -> 'ok'
- '{{1 > 0 && 1 < 1 ? ok : notOk)}}' -> 'not ok'
Advanced
You can use this syntax to get access to object value. This work only when you use in template one replacing syntax. Value will be stored in onlyOneParamValue attribute.