SoFunction
Updated on 2025-02-28

A brief discussion on the solution to display null in laytpl template and simple js expression

laytpl template syntax

{{ }} outputs a normal field, not escapes html official description, but null will be displayed when empty

laytpl template Solution to null display null

{{}} When giftName is empty in the template, a null string will be displayed on the page.

1 You can directly use a tri-item expression in the template to determine whether the string is empty.

as follows:

{{!?" ":}}

2 There is another method, using a || operator

{{||" "}} will be displayed as an empty string when empty

{{||"No giveaway"}} will be displayed when empty No giveaway Double quotes or single quotes wrapped strings are OK, but not without

{{|| }} Report an error directly without quotes Laytpl Error: SyntaxError: Unexpected token )

There is another exception that you can do without quotes

{{|| null }} and {{}} are no different

{{# JavaScript Expression }}

JS statement. Generally used for logical processing. Start with a separator plus a # sign. Note: If you want to output a function, the correct way to write it is: {{ fn() }}, instead of: {{# fn() }}

Try the if else syntax of the laytpl template

This is an example on the official website

{{# if(true){ }}
 start date:{{ fn() }}
{{# } else { }}
 Deadlined
{{# } }} 

At first glance, I'll make it

{{#      if(true){              }}
               start date
{{#        } else {             }} 
               Deadlined
{{#        }                    }}

Now it's clear at a glance

/doc/modules/