HTL

转载自:HTL 块语句

BLOCK

data-sly-template
data-sly-set, data-sly-test data-sly-use
data-sly-call
data-sly-text
data-sly-element, data-sly-include data-sly-resource
data-sly-unwrap
data-sly-list, data-sly-repeat
data-sly-attribute

@应该是传参的意思

data-sly-use

可以直接等于路径来调用资源,例如

<div data-sly-use.product=“/etc/commerce/product/12345”>
  ${ product.title }
</div>

data-sly-set

添加元素

<span data-sly-set.profile="${user.profile}">Hello, ${profile.firstName} ${profile.lastName}!</span>

data-sly-text

将内容替换

<p data-sly-text="${properties.jcr:description}">Lorem ipsum</p>
结果为
<p>${properties.jcr:description}</p>

data-sly-attribute

添加属性

<div title="${properties.jcr:title}"></div>
等同于
<div title="Lorem Ipsum" data-sly-attribute.title="${properties.jcr:title}"></div>

data-sly-element

替换标签

<h1 data-sly-element="${h2}">text</h1>
h1会变为h2

data-sly-test

根据条件判断是否显示内容

<div data-sly-test="${properties['jcr:title'].length > 3}">Title is longer than 3</div>
<div data-sly-test="${properties['jcr:title'].length >= 0}">Title is longer or equal to zero </div>

data-sly-repeat

循环输出

data-sly-list

循环输出

data-sly-resource

这几个都看不懂他里面的值到底什么意思
什么${'path/to/resource'}
什么${currentPage.listChildren}了,莫名其妙

data-sly-include

将内容替换为其他html

template & call

template定义模板
call调用模板

<template data-sly-template.one>blah</template>
<div data-sly-call="${one}"></div>

data-sly-unwrap

没什么用,去除元素的

HTL Expression Language

Variables 变量

这几种方式都可以

${currentPage.title}  
${currentPage['title']} or ${currentPage["title"]}

括号记号可用于访问包含无效标识符字符的属性,如以下示例中的空格字符:
${properties['my property']}

Literals 文本

布尔/数字/字符串(转义)/数组

Operators 运算符

NOT

<p data-sly-test="${!currentPage.hasChild}">current page has no children</p>

AND

验证第一个是否为假,否则上替补

(注意下面的例子用的是test来判断的):
${varOne && varTwo} returns varOne if it is falsy; otherwise, it returns varTwo.

<div data-sly-test="${properties.jcr:title && properties.jcr:description}">
    <h1>${properties.jcr:title}</h1>
    <p>${properties.jcr:description}</p>
</div>

---

在class中只有当两个都为true时才生效:
<div class="${logic.showClass && logic.className}">...</div>

OR

验证第一个是否为真,否则上替补

${varOne || varTwo} returns varOne if it is truthy; otherwise, it returns varTwo.

可以直接在表达式中进行判断
${header.about || about.jcr:title}

Conditional(ternary) Operator三元运算符

Comparison Operators 比较运算符

Options

Expression options can act on the expression and modify it, or serve as parameters when used in conjunction with block statements.
可以act表达式和修改他,或者作为块语句的参数

---所有@后面都是一个选项??
${myVar @ optOne}
---可以是文本或变量
${myVar @ optOne=someVar}
${myVar @ optOne='bar'}
${myVar @ optOne=10}
${myVar @ optOne=true}
---多个,逗号分隔。也可以只有选项
${@ optOne, optTwo=bar}
---字符串
${'Page {0} of {1}' @ format=[current, total]}

URL

Other

${['one', 'two'] @ join='; '}转为文本
posted @ 2021-01-14 16:24  lwxx  阅读(472)  评论(0)    收藏  举报