AEM 6.5 无法将自定义变量直接传递给 Java 使用 API

问题描述 投票:0回答:1
aem sightly client-library
1个回答
0
投票

做时:

data-sly-call="${clientlibsDeferred.js @ categories= 'testCategory', identifier='testIdentifier', loading='defer'}

您实际上是在由

js
定义的模板文件中调用名为
clientlibsDeferred
的模板(很可能是 https://github.com/nateyolles/aem-clientlib-async/blob/master/demo/ui.apps/ src/main/content/jcr_root/apps/clientlib-async/sightly/templates/clientlib.html#L41-L50):

<template data-sly-template.js="${@ categories='Client Library categories',
                                    loading='Accepts async and defer',
                                    onload='JavaScript to run for async and defer',
                                    crossorigin='Accepts anonymous and use-credentials'}">
    <section data-sly-test="${request.getResourceResolver}"
             data-sly-use.clientlib="${'/apps/clientlib-async/sightly/templates/graniteClientLib.html'}"
             data-sly-call="${clientlib.include @ categories=categories, mode='js', loading=loading, onload=onload, crossorigin=crossorigin}"
             data-sly-unwrap>
    </section>
</template>

反过来,将从

include
调用
clientlib
模板(位于
/apps/clientlib-async/sightly/templates/graniteClientLib.html
- https://github.com/nateyolles/aem-clientlib-async/blob/master/demo/ui.apps /src/main/content/jcr_root/apps/clientlib-async/sightly/templates/graniteClientLib.html#L26-L33):

<template data-sly-template.include="${@ categories='Client Library categories',
                                         mode='optional: JS or CSS, case-insensitve',
                                         loading='optional: JS async or defer',
                                         onload='optional: JS to run for async and defer',
                                         crossorigin='optional: accepts anonymous and use-credentials'}"
    data-sly-use.clientlib="${'apps.clientlib_async.sightly.templates.ClientLibUseObject' @ categories=categories, mode=mode, loading=loading, onload=onload, crossorigin=crossorigin}">
${clientlib.include @ context='unsafe'}
</template>

这是将实例化

ClientLibUseObject
并传递参数的代码,正如您所看到的,
identifier
并未在此链上传递。 您可以跳过该链并自己实例化
ClientLibUseObject
(传递
identifier
),然后调用其
include
方法。

© www.soinside.com 2019 - 2024. All rights reserved.