Skip to content

Conformance Examples 0.1.0 — Render: literals-blocks

if-true-literal-renders-body

{{#if true}} always renders its body.

Template

{{#if true }}yes{{/if}}

Output

yes

if-false-literal-renders-else

{{#if false}} with an else arm renders the else body.

Template

{{#if false }}yes{{else}}no{{/if}}

Output

no

if-false-literal-no-else-emits-nothing

{{#if false}} with no else arm emits nothing.

Template

[{{#if false }}yes{{/if}}]

Output

[]

if-zero-literal-is-falsy

Numeric 0 literal is falsy; the else body renders.

Template

{{#if 0 }}truthy{{else}}falsy{{/if}}

Output

falsy

if-negative-zero-decimal-is-falsy

Numeric -0.0 literal is falsy (matches existing 0.0 == -0.0 truthiness rule).

Template

{{#if -0.0 }}truthy{{else}}falsy{{/if}}

Output

falsy

if-nonzero-number-literal-is-truthy

A nonzero numeric literal is truthy.

Template

{{#if 1 }}truthy{{else}}falsy{{/if}}

Output

truthy

if-empty-string-literal-is-falsy

An empty-string literal is falsy.

Template

{{#if "" }}truthy{{else}}falsy{{/if}}

Output

falsy

if-nonempty-string-literal-is-truthy

A non-empty string literal is truthy (including "false" as a string).

Template

{{#if "false" }}truthy{{else}}falsy{{/if}}

Output

truthy

if-null-literal-is-falsy

The null literal is falsy.

Template

{{#if null }}truthy{{else}}falsy{{/if}}

Output

falsy

if-else-if-with-literal-second-arm-wins

{{else if}} accepts a literal expression; when the first arm is falsy and the {{else if}} literal is truthy, the second arm wins.

Template

{{#if cond }}A{{else if true }}B{{/if}}

Context

{
    "cond": false
}

Output

B

if-else-if-with-falsy-literal-falls-through

A falsy {{else if}} literal falls through to the next arm.

Template

{{#if a }}A{{else if false }}B{{else}}Z{{/if}}

Context

{
    "a": false
}

Output

Z

unless-null-literal-renders-body

{{#unless null}} renders its body (null is falsy).

Template

{{#unless null }}yes{{/unless}}

Output

yes

unless-truthy-string-literal-renders-else

{{#unless "hi"}} renders its else body (a non-empty string is truthy).

Template

{{#unless "hi" }}body{{else}}else{{/unless}}

Output

else

unless-zero-literal-renders-body

{{#unless 0}} renders its body (0 is falsy).

Template

{{#unless 0 }}yes{{else}}no{{/unless}}

Output

yes

with-string-literal-pushes-primitive

{{#with "hi"}} pushes the string primitive onto the context stack; {{ this }} inside the body resolves it.

Template

{{#with "hi" }}{{ this }}{{/with}}

Output

hi

with-number-literal-pushes-primitive

{{#with 42}} pushes the number primitive; {{ this }} inside renders "42".

Template

{{#with 42 }}{{ this }}{{/with}}

Output

42

with-true-literal-pushes-primitive

{{#with true}} pushes the boolean primitive; {{ this }} inside renders "true".

Template

{{#with true }}{{ this }}{{/with}}

Output

true

with-null-literal-pushes-null-context

{{#with null}} pushes a null context; {{ this }} renders "null" by the null-context convention.

Template

{{#with null }}{{ this }}{{/with}}

Output

null

with-string-literal-then-non-this-identifier-is-null

A non-this identifier inside {{#with primitive}} soft-fails and resolves to null (matches B1 identifier-resolution behavior for non-container contexts).

Template

{{#with "hi" }}{{ name }}{{/with}}

Output

null

each-string-literal-falls-into-else

A string literal is not an iterable container; {{#each}} falls into the else arm.

Template

{{#each "hi" }}body{{else}}none{{/each}}

Output

none

each-number-literal-falls-into-else

A number literal is not an iterable container; {{#each}} falls into the else arm.

Template

{{#each 42 }}body{{else}}none{{/each}}

Output

none

each-true-literal-falls-into-else

A boolean literal is not an iterable container; {{#each}} falls into the else arm.

Template

{{#each true }}body{{else}}none{{/each}}

Output

none

each-null-literal-falls-into-else

A null literal is not an iterable container; {{#each}} falls into the else arm.

Template

{{#each null }}body{{else}}none{{/each}}

Output

none

each-null-literal-no-else-emits-nothing

A non-iterable literal with no else arm emits nothing.

Template

[{{#each null }}body{{/each}}]

Output

[]

Source fixture: render/literals-blocks.json