【问题标题】:data-sly-call in sightly not invokingdata-sly-call 似乎没有调用
【发布时间】:2015-02-21 12:48:50
【问题描述】:

我正在尝试 [a link]http://docs.adobe.com/docs/en/aem/6-0/develop/sightly/use-api-in-java.html 提供的示例示例。我创建了组件 SightlyTest,其中对模板的 data-sly-call 不起作用。以下是我在组件中的文件: extra.html

<template data-sly-template.extra="${@ text}"
          data-sly-use.extraHelper="${'ExtraHelper' @ text=text}">
    <p>${extraHelper.reversedText}</p>
</template>

ExtraHelper.java

package apps.AEMProject.components.content.SightlyTest;
import com.adobe.cq.sightly.WCMUse;
public class ExtraHelper extends WCMUse {
    private String reversedText;
    public String getReversedText() {
        return reversedText;
    }
    @Override
    public void activate() throws Exception {
        String text = get("text", String.class);
        reversedText = new StringBuilder(text).reverse().toString();
        System.out.print("reversedText ::: "+reversedText);
    }
}

SightlyOp.java

package apps.AEMProject.components.content.SightlyTest;
import com.adobe.cq.sightly.WCMUse;
public class SightlyOp extends WCMUse {
    private String lowerCaseTitle;
    private String lowerCaseDescription;
    @Override
    public void activate() throws Exception {
        lowerCaseTitle = getProperties().get("title", "").toLowerCase();
        lowerCaseDescription = getProperties().get("description", "").toLowerCase();
    }

    public String getLowerCaseTitle() {
        return lowerCaseTitle;
    }

    public String getLowerCaseDescription() {
        return lowerCaseDescription;
    }

}

SightlyTest.html

<div data-sly-use.sg="SightlyOp"
     data-sly-use.extra="extra.html">

    <h1>${sg.lowerCaseTitle}</h1>
    <p>${sg.lowerCaseDescription}</p>
    <div data-sly-call="${extra @ text=properties.description}"></div>

</div>

sg.lowerCaseTitle 和 sg.lowerCaseDescription 工作正常,但数据狡猾调用没有显示 谢谢

【问题讨论】:

  • 嗨,有人对此有任何想法吗?谢谢

标签: aem sightly


【解决方案1】:

在 SightlyTest.html 中试试这个,

<div data-sly-use.sg="SightlyOp" data-sly-use.extra1="extra.html">
    <h1>${sg.lowerCaseTitle}</h1>
    <p>${sg.lowerCaseDescription}</p>
    <div data-sly-call="${extra1.extra @ text=properties.description}"></div>
</div>

修改为 data-sly-use.extra1 以区分变量和被调用的模板。

【讨论】:

    【解决方案2】:

    我意识到我来晚了一点,但我想扩展Aditya's answer

    将文件 extra.html 想象成更像是data-sly-templates 的“库”,因为它可以包含任意数量的文件(每个文件都有不同的名称)。因此,当您“使用”extra.html 文件时,您将这些模板导入到您在 use 语句中提供的命名空间中。然后,您可以使用该“命名空间”调用模板。

    <div data-sly-use.sg="SightlyOp"
         data-sly-use.extra="extra.html">
         <!--/*${extra} is now a namespace for the templates in extra.html. (you can name it whatever you like for more clarity*/-->
    
        <h1>${sg.lowerCaseTitle}</h1>
        <p>${sg.lowerCaseDescription}</p>
    
        <!--/*since your template is called extra, and it's in the namespace called extra you call it with ${extra.extra}*/-->
        <div data-sly-call="${extra.extra @ text=properties.description}"></div>
    
    </div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-12
      • 2018-03-27
      • 1970-01-01
      • 2014-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多