Skip to content

Commit

Permalink
Documented typecasting filters
Browse files Browse the repository at this point in the history
  • Loading branch information
lindseydiloreto committed Jun 11, 2018
1 parent b525f42 commit daba197
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

Making twig do things it really shouldn't. Twig is not intended to be a general purpose programming language, and there are some things that really don't belong in the language. This plugin adds a few of those things anyway.

- {% break %}, {% continue %}, and {% return %} tags
- `{% break %}`, `{% continue %}`, and `{% return %}` tags
- `is numeric` test
- `json_decode` filter
- `array_splice` filter
- `string` and `s` filters
- `float` and `f` filters
- `int` and `i` filters
- `bool` and `b` filters

## Installation

Expand Down Expand Up @@ -55,6 +59,7 @@ A macro with a `{% return %}` tag will return whatever the return value is (whic

### Tests
- **Numeric**

Test whether given value is numeric (behaviour like PHP 7 `is_numeric`). (Note that as of PHP 7, hexadecimal strings are not considered numeric)

#### Examples
Expand All @@ -74,9 +79,27 @@ A macro with a `{% return %}` tag will return whatever the return value is (whic

### Filters
- **json_decode**

Decode json string, returning php associative arrays. Uses the PHP [json_decode](http://php.net/manual/en/function.json-decode.php) function

- **array_splice**

Remove a portion of an array and replace it with something else. Uses the PHP [array_splice](http://php.net/manual/en/function.array-splice.php) function. Note that unlike the php function, this filter returns the modified array rather than the extracted elements. The original array is unchanged. Since the implementation requires copying the array, this will be less efficient than the raw php function. The **array_splice** filter is passed an `offset`, an optional `length`, and an optional `replacement`.

- **string** or **s**

Typecast variable as a string.

- **float** or **f**

Typecast variable as a float.

- **int** or **i**

Typecast variable as an integer.

- **bool** or **b**

Typecast variable as a boolean.

Brought to you by [Marion Newlevant](http://marion.newlevant.com)

0 comments on commit daba197

Please sign in to comment.