Blocks Code
Handlebars
Output Method "HTML + Handlebars" supports Handlebars syntax and you can easily output value of your block controls:
Handlebars
{{#if control_name}}
<p>The value is True</p>
{{else}}
<p>The value is False</p>
{{/if}}
Available helpers
There are available Handlebars helpers for your output code. You can find it in the official documentation https://handlebarsjs.com/builtin_helpers.html. In addition to default helpers we added also custom.
truncate
Truncate the string value and add three dots in the end of result string if needed.
Handlebars
{{truncate "your string" 7 "true"}}
{{truncate control_name 7 "true"}}
Available attributes:
Name | Description |
---|---|
String | String to truncate |
Limit | Number of characters to be left |
Dots | Show three dots in the end |
compare
Compare 2 values and show/hide content.
Handlebars
{{#compare 1 "===" 2}}
Show if true
{{/compare}}
{{#compare control_1 ">" control_2}}
Show if the value in first control larger that in second
{{/compare}}
Available attributes:
Name | Description |
---|---|
First Value | First value on the left side to compare |
Operator | Logical operator to compare. Supported operators: == , === , != , !== , < , > , <= , >= , && , || |
Second Value | Second value on the right side to compare |
math
Mathematical operations with 2 values.
Handlebars
{{math 1 "+" 2}}
{{math control_1 "-" control_2}}
Available attributes:
Name | Description |
---|---|
First Value | First value on the left side to math |
Operator | Logical operator to math. Supported operators: + , - , * , / , % |
Second Value | Second value on the right side to math |
date_i18n
Format date.
Handlebars
{{date_i18n "F j, Y H:i" "2018-09-16 15:35"}}
{{date_i18n control_with_format control_with_time}}
Available attributes:
Name | Description |
---|---|
Format | Date format to convert. Example: F j, Y H:i |
Date | Date string |
do_shortcode
The same function as WordPress's do_shortcode
.
Handlebars
{{{do_shortcode "my_shortcode" this}}}
Name | Description |
---|---|
Name | Shortcode name |
Attributes | Shortcode attributes. Use this to add all block attributes inside your shortcode |
Custom Helpers
You can add custom Handlebars helpers and use it in blocks output:
PHP
function my_custom_lazyblock_handlebars_helper ( $handlebars ) {
// date_i18n.
// {{my_test_helper 'test value'}}.
$handlebars->registerHelper( 'my_test_helper', function( $val ) {
return '<p>My test helper: ' . $val . '</p>';
} );
}
add_action( 'lzb/handlebars/object', 'my_custom_lazyblock_handlebars_helper' );