简体   繁体   English

AEM:将属性从 HTML 内的吊索 model 传递给视觉组件

[英]AEM: passing properties to sightly component from sling model inside HTML

We have a requirement wherein we need to create a template dynamically using the sling model response.我们有一个要求,我们需要使用吊索 model 响应动态创建模板。

The challenge here is we have got some common components that we want to use for building up our template.这里的挑战是我们有一些我们想要用于构建模板的通用组件。

Is there a way that I can set the common components properties using slightly.有没有一种方法可以让我稍微使用一下来设置通用组件的属性。

Any help is appreciated.任何帮助表示赞赏。

You can initialise the Sling Model with the HTL Use API :您可以使用 HTL 初始化 Sling Model 使用 API

<sly data-sly-use.myModel="mypackage.MyModel">

and then access it's properties/methods in HTL Expressions :然后在HTL Expressions中访问它的属性/方法:

${myModel.myProperty}

For a simple example, have a look at the title component for AEM: https://github.com/adobe/aem-core-wcm-components/blob/master/content/src/content/jcr_root/apps/core/wcm/components/title/v2/title/title.html举个简单的例子,看看 AEM 的标题组件: https://github.com/adobe/aem-core-wcm-components/blob/master/content/src/content/jcr_root/apps/core/wcm /components/title/v2/title/title.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM