-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
docs/designers/language-modifiers/language-modifier-json-encode.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# json_encode | ||
|
||
Transforms a value into a valid JSON string. | ||
|
||
## Basic usage | ||
```smarty | ||
{$user|json_encode} | ||
``` | ||
Depending on the value of `$user` this would return a string in JSON-format, e.g. `{"username":"my_username","email":"my_username@smarty.net"}`. | ||
|
||
|
||
## Parameters | ||
|
||
| Parameter | Type | Required | Description | | ||
|-----------|------|----------|-------------------------------------------------------------------------------------------| | ||
| 1 | int | No | bitmask of flags, directly passed to [PHP's json_encode](https://www.php.net/json_encode) | | ||
|
||
|
||
## Examples | ||
|
||
By passing `16` as the second parameter, you can force json_encode to always format the JSON-string as an object. | ||
Without it, an array `$myArray = ["a","b"]` would be formatted as a javascript array: | ||
|
||
```smarty | ||
{$myArray|json_encode} # renders: ["a","b"] | ||
{$myArray|json_encode:16} # renders: {"0":"a","1":"b"} | ||
``` |
32 changes: 32 additions & 0 deletions
32
docs/designers/language-modifiers/language-modifier-number-format.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# number_format | ||
|
||
Allows you to format a number using decimals and a thousands-separator. By default, the number of decimals is 0 | ||
and the number is rounded. | ||
|
||
## Basic usage | ||
```smarty | ||
{$num = 2000.151} | ||
{$num|number_format} # renders: 2,000 | ||
``` | ||
|
||
|
||
## Parameters | ||
|
||
| Parameter | Type | Required | Description | | ||
|-----------|--------|----------|---------------------------------------| | ||
| 1 | int | No | number of decimals (defaults to 0) | | ||
| 2 | string | No | decimal separator (defaults to ".") | | ||
| 3 | string | No | thousands-separator (defaults to ",") | | ||
|
||
|
||
## Examples | ||
|
||
```smarty | ||
{$num = 2000.151} | ||
{$num|number_format:2} # renders: 2,000.15 | ||
``` | ||
|
||
```smarty | ||
{$num = 2000.151} | ||
{$num|number_format:2:".":""} # renders: 2000.15 | ||
``` |
35 changes: 35 additions & 0 deletions
35
docs/designers/language-modifiers/language-modifier-round.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# round | ||
|
||
Rounds a number to the specified precision. | ||
|
||
## Basic usage | ||
```smarty | ||
{3.14|round} # renders: 3 | ||
``` | ||
|
||
```smarty | ||
{3.141592|round:2} # renders: 3.14 | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Required | Description | | ||
|-----------|------|----------|---------------------------| | ||
| 1 | int | No | precision (defaults to 0) | | ||
| 2 | int | No | mode (defaults to 1) | | ||
|
||
If 'precision' is negative, the number is rounded to the nearest power of 10. See examples below. | ||
|
||
The parameter 'mode' defines how the rounding is done. By default, 2.5 is rounded to 3, whereas 2.45 is rounded to 2. | ||
You usually don't need to change this. For more details on rounding modes, | ||
see [PHP's documentation on round](https://www.php.net/manual/en/function.round). | ||
|
||
## Examples | ||
|
||
By passing `16` as the second parameter, you can force json_encode to always format the JSON-string as an object. | ||
Without it, an array `$myArray = ["a","b"]` would be formatted as a javascript array: | ||
|
||
```smarty | ||
{$myArray|json_encode} # renders: ["a","b"] | ||
{$myArray|json_encode:16} # renders: {"0":"a","1":"b"} | ||
``` |
14 changes: 14 additions & 0 deletions
14
docs/designers/language-modifiers/language-modifier-str-repeat.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# str_repeat | ||
|
||
Repeats the given value n times. | ||
|
||
## Basic usage | ||
```smarty | ||
{"hi"|str_repeat:2} # renders: hihi | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Required | Description | | ||
|-----------|------|----------|-----------------------| | ||
| 1 | int | yes | number of repetitions | |
9 changes: 9 additions & 0 deletions
9
docs/designers/language-modifiers/language-modifier-strlen.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# strlen | ||
|
||
Returns the length (number of characters) in the given string, including spaces. | ||
|
||
## Basic usage | ||
```smarty | ||
{"Smarty"|strlen} # renders: 6 | ||
{156|strlen} # renders: 3 | ||
``` |
25 changes: 25 additions & 0 deletions
25
docs/designers/language-modifiers/language-modifier-substr.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# substr | ||
|
||
Returns a part (substring) of the given string starting at a given offset. | ||
|
||
## Basic usage | ||
```smarty | ||
{"Smarty"|substr:2} # renders: arty | ||
{"Smarty"|substr:2:3} # renders: art | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Required | Description | | ||
|-----------|------|----------|-----------------------------------------------------| | ||
| 1 | int | yes | offset (zero based, can be negative) | | ||
| 2 | int | no | length of substring returned (unlimited of omitted) | | ||
|
||
|
||
## Examples | ||
|
||
When used with a negative offset, the substring starts n characters from the end of the string counting backwards. | ||
```smarty | ||
{"Smarty"|substr:-2} # renders: ty | ||
{"Smarty"|substr:-2:1} # renders: t | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters