在 Scriban 中格式化 HTML

问题描述

将 scriban 与 SXA 一起使用,我们注意到生成的 HTML 有很多空格,例如:

<div id=”dv1”>


           <div id=”dv2”>

这是因为在使用 id=de2 渲染 div 之前,在 scriban 中我们有 if 条件,有没有办法格式化 html ?

解决方法

如果您发布了您正在使用的 Scriban 代码段,将会很有帮助。我怀疑您需要在 ~ 代码块的末尾使用 if 运算符,如here

所述

例如:

<div 1>


{{- #eat all whitespace to left including newlines
    if true
    #eat whitespace but not newlines to right  ~}}

    <div 2>
{{end}}
 

输出

<div 1>
    <div 2>

您可以使用 this 工具尝试格式化。