2014-12-23 5 views
0

Я пытался попробовать пример, приведенный в [link] http://docs.adobe.com/docs/en/aem/6-0/develop/sightly/use-api-in-java.html. Я создал компонент SightlyTest, в котором нечеткий вызов в шаблон не работает. Ниже приведены мои файлы внутри компонента: extra.htmldata-sly-call in viewly не вызывает

<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 работает нормально, но ничего отображение данных, втихаря вызовет Спасибо

+0

Привет, У кого-нибудь есть представление об этом. благодаря –

ответ

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> 

Modified для данных-лукавой использования .extra1, чтобы различать переменную и вызываемый шаблон.

0

Я понимаю, что я пришел на вечеринку немного поздно, но я хотел бы расширить на Aditya's answer.

Think файла extra.html больше как «библиотеки» data-sly-templates, а, так как она может содержать как многие из них, как вы хотите (каждый с другим именем). Поэтому, когда вы «используете» файл extra.html, вы как бы импортируете эти шаблоны в пространство имен, которое вы указываете в инструкции использования. Затем вы можете вызвать шаблоны, используя это «пространство имен».

<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>