Aem 模板默认值

Aem 模板默认值,aem,sightly,htl,Aem,Sightly,Htl,模板/调用模式是否包含默认值 给定一个模板: template.html <template data-sly-template.tmpl=${ @ foo='bar', baz='buzz' }> <p>the value of foo is ${foo}> </template> foo的值是${foo}> 假设调用它时使用: <sly data-sly-use.myTemplate="template.html" data

模板/调用模式是否包含默认值

给定一个模板:

template.html

<template data-sly-template.tmpl=${ @ foo='bar', baz='buzz' }>
  <p>the value of foo is ${foo}>
</template>

foo的值是${foo}>
假设调用它时使用:

<sly data-sly-use.myTemplate="template.html"
     data-sly-call="${myTemplate.tmpl}"/>

我想要一个输出:

<p>the value of foo is bar</p>
foo的值是bar

这可能吗?我想在助手中使用它,在助手中,我有一个默认情况下通常为“true”的标志,但在某些情况下,我希望能够设置为false

谢谢

根据,您不能以这种方式设置默认参数。模板块表达式中的值是用法提示

当模板调用中缺少某些参数时,该参数将初始化为模板中的空字符串

但是,可以使用逻辑OR运算符在HTL块表达式中设置默认值。以您的例子:

<template data-sly-template.tmpl=${ @ foo='foo hint', baz='buzz hint' }>
    <p>the value of foo is ${foo || 'bar'}</p>
</template>

foo的值是${foo | |'bar'}

根据,您不能以这种方式设置默认参数。模板块表达式中的值是用法提示

当模板调用中缺少某些参数时,该参数将初始化为模板中的空字符串

但是,可以使用逻辑OR运算符在HTL块表达式中设置默认值。以您的例子:

<template data-sly-template.tmpl=${ @ foo='foo hint', baz='buzz hint' }>
    <p>the value of foo is ${foo || 'bar'}</p>
</template>

foo的值是${foo | |'bar'}