首页 > 解决方案 > 从吊索模型获取列表到 HTML 页面的 HTL 代码

问题描述

我创建了 Sling 模型,它正在获取根页面及其子页面。我在 List 中添加了所有页面的标题和描述。

我的豆类如下

Items(String title, String description, List<Items>)

Items我在我的吊索模型中 有这个 bean 类的列表,并在这个列表中添加了内容。List<Items>in 参数用于将子页面存储在其中。

如何在我的 HTL 代码中获取此列表值以在页面上使用视觉显示它?这将是什么代码?

标签: aemsightly

解决方案


您通常会使用 getter 方法公开时间列表:

public List<Items> getItems() { ... }

假设每个项目还公开了title和的吸气剂description

public String getTitle() { ... }
public String getDescription() { ... }

然后你可以使用你的模型:

<ul data-sly-use.myModel="MyModelClass" data-sly-list="myModel.items">
    <li>${item.title} - ${item.description}</li>
</ul>

HTL 规范中还有更多示例。


推荐阅读