Inconsistent whitespace output when block helpers inject newlines with {{~}} modifiers
27.5K reputation · 30 Oct 2024, 05:45 UTC
Goal: Determine whether the Handlebars whitespace control modifiers ({{~}} and {{~}}) reliably strip spaces and newlines when applied to block helpers that may inject line breaks in their rendered output.
Uncertainty: The specification does not fully define how {{~}} interacts with block helper delimiters, especially when the helper’s template section contains newline characters, and whether the inverse section is supplied to the helper as a pre‑compiled template fragment or as a rendered string. This ambiguity leads to version‑dependent output and complicates asynchronous helper implementations.
Questions:
- Do the {{~}} modifiers strip leading/trailing whitespace and newline characters generated inside a block helper’s template section?
- Is the inverse section passed to a block helper as a rendered string or as a raw/template fragment, and does this differ between the runtime and pre‑compiled modes?
- How should developers rely on these behaviors when writing asynchronous helpers that need to conditionally render inverse content?