Template Engine Samples
WebInStats Template Engine
WebInStats Template Engine Basic Usage
We are going to use the variables below for examples
Variables = {
“name”:”John”,
“recommended_product_ids”:”12345,87644,12345″,
“date”:”2019-04-23 12:34:00″,
“total_price”:4800.241,
“quantity”:2,
“products”:[
{“id”:1,”name”:”First Product”,”price”:”1200.241″} ,
{“id”:2,”name”:”Second Product”,”price”:”3600″}
]
}
Sample : Hello {{name}},
Returns : Hello John,
Write different texts if value exists or not exists
You can use # to check if variable has a value. To add default value (if variable not exists or empty) you can use ^ in front of variable
Sample : Hello {{#name}}Your Name is {{name}} {{/name}} {{^name}} NoName; {{/name}}
Returns : Hello Your Name is John
Conditions
You can use conditions to write different text in different values You not use if conditions in arrays.
Sample : {{#if $name==”John”}} Hello my dear friend John{{else}}Hello {{name}} {{/if}}
Returns : Hello my dear friend John
Sample : {{#if $quantity<3}} Only A few product left. Hurry up.{{else}} It’s in stock. {{/if}}
Returns : Only A few product left. Hurry up.
Array Values
Sample : {{#products}}### {{.name}} – {{.id}} – {{.price}} @@@{{/products}}
Returns : ###First Product – 1 – 1200 @@@ ###Second Product – 2 – 3600 @@@
Helpers
Helpers allows you to modify variable or text block value.
Helper types are :
@lowercase : {{name | @lowercase}} returns : john
@uppercase : {{name | @uppercase}} returns : JOHN
@camelcase : {{@camelcase}} hELLo {{name}} {{/@camelcase}} returns : Hello John
@round : {{@round}}18374.44247{{/@round}} returns : 18374.44
@round0 :{{@round0}}18374.44247{{/@round0}} returns : 18374
@numberformat : {{total_price | @numberformat}} returns : 4,800.24
@numberformat0 :{{total_price | @numberformat0}} returns : 4,800
@numberformatcomma : {{total_price | @numberformatcomma}} returns : 4.800,24
@numberformatcomma0 :{{total_price | @numberformatcomma}} returns : 4.800
@dateformat : {{date |@dateformat}} returns : 23/04/2019
@datetimeformat : {{date |@datetimeformat}} returns : 23/04/2019 12:34:00
@dateformat_monthfirst : {{date |@dateformat_monthfirst}} returns : 04/23/2019
@datetimeformat_monthfirst : {{date |@datetimeformat_monthfirst}} returns : 04/23/2019 12:34:00
@substr10 : {{@substr10}}1234567890123456789012345678901234567890{{/substr10}} returns : 1234567890
@substr15 : {{@substr15}}1234567890123456789012345678901234567890{{/substr10}} returns :123456789012345
@substr20 : {{@substr20}}1234567890123456789012345678901234567890{{/substr10}} returns :123456789012345678901234567890
@product_detail : This helper gets product information from BIG Data system using product Ids.
{{!!! @product_detail | recommended_product_ids | recommended_product_array}}
{{#recommended_product_array}}
{{.PRODUCT_ID}}
{{.PRODUCT_IS_ACTIVE}}
{{.PRODUCT_TITLE}}
{{.PRODUCT_SUBTITLE}}
{{.PRODUCT_SELLER_NAME}}
{{.PRODUCT_SELLER_TRANSACTION_COUNT}}
{{.PRODUCT_SELLER_PERCENT}}
{{.PRODUCT_DESCRIPTION}}
{{.PRODUCT_URL}}
{{.PRODUCT_URL_MOBILE}}
{{.PRODUCT_URL_IPHONE}}
{{.PRODUCT_URL_ANDROID}}
{{.PRODUCT_IMAGE}}
{{.PRODUCT_AVAILABLE}}
{{.PRODUCT_MARKET_PRICE}}
{{.PRODUCT_SALE_PRICE}}
{{.PRODUCT_TYPE}}
{{.PRODUCT_CATEGORY}}
{{.PRODUCT_CONDITION}}
{{.PRODUCT_SHIPPING_FEE}}
{{.PRODUCT_SHIPPING_DATE}}
{{.PRODUCT_STOCK_LEFT}}
{{.PRODUCT_LABEL1}}
{{.PRODUCT_LABEL2}}
{{.PRODUCT_LABEL3}}
{{.PRODUCT_LABEL4}}
{{.PRODUCT_LABEL5}}
{{/recommended_product_array}}
You can use helpers in 2 different format. If you need to change variable only, you can use 1. option. If you need to change text block you can use 2. option.
1-) {{name | @uppercase}} Returns : JOHN
2-) {{@uppercase}} hEllO {{name}} {{/@uppercase}} Returns : HELLO JOHN