我是AEM的新手,考虑我的js将返回itemList(例如:var itemList = list.getItems();)。 每个项目的骨架都是:
interface Item {
/**
* Get the item's title.
*
* @return the title
*/
@Nonnull
String getTitle();
/**
* Get the item's localized title.
*
* @param locale the locale for localization
*
* @return the title
*/
@Nonnull
String getTitle(Locale locale);
/**
* Get the item's value.
*
* @return the value
*/
@Nonnull
String getValue();
}
如何获取基于区域设置的标题(即调用getTitle(locale)
)来代替以下${list.title}
标记的HTML代码中提到的select
(我需要两个标题(区域设置)和itemlist中的值):
选项值=" $ {list.value}"> $ {list.title}
答案 0 :(得分:0)
从Sightly,您无法访问带参数的方法。
但是,在Use-API中,可以使用与Sightly执行上下文中相同的全局变量,也可以将参数传递给Use-API的初始化。
在Java代码中,您可以使用类似的方式访问页面语言:
PageManager pageManager = request.getResourceResolver().adaptTo(PageManager.class);
Page currentPage = pageManager.getContainingPage(request.getResource());
Locale locale = currentPage.getLanguage(false);
否则,要将参数传递给Java Use-API,它就是这样的:
<div data-sly-use.foo="${'Foo' @ locale='es'}">
<h1>${foo.titleLocalized}</h1>
</div>
和相应的Java:
public class Foo extends WCMUsePojo {
private String locale;
@Override
public void activate() throws Exception {
String locale = get("locale", String.class);
}
public String titleLocalized() {
...
}
}