我必须将一些额外的数据向下传递到一个小部件,以确定我的一些用户的某些所有权/可访问性选项。我按照此处的说明设置助手来传递数据:
不过,我遇到了一些问题。以下代码用于小部件 index.js 文件:
module.exports = {
extend: 'apostrophe-widgets',
label: 'Unsubscribed Content',
//contextualOnly: true,
construct: function(self, options) {
self.addHelpers({
isSubscribed: function() {
var req = self.apos.templates.contextReq;
var isSubbed = false;
var currentYear = new Date().getFullYear();
for(var i = 0; i < req.user.subscriptions.length; i++) {
if (req.user.subscription[i].subscriptionYear == currentYear) {
isSubbed = true;
}
}
return isSubbed;
}
});
},
addFields: [
{
type: 'area',
name: 'area',
label: 'Area',
contextual: true
}
]
};
我在这里没有遇到任何错误,但是当我尝试从小部件的模板实际访问帮助程序时,它找不到方法。我尝试了以下方法来访问它并尝试取回值:
{{ apos.isSubscribed() }}
{{ isSubscribed() }}
{% if apos.isSusbcribed() %}
{% if isSubscribed() %}
但它们都给我以下错误之一:
错误:无法调用未定义或错误的 apos["isSubscribed"]
错误:无法调用未定义或错误的 clap
我是不是做错了什么?
谢谢!
最佳答案
在您的模板中,您应该能够调用 apos.modules['my-module-widgets'].isSubscribed
Apostrophe 也有一个 console.log
包装器,可以用在像 {{ apos.log(somethingOfInterest) }}
这样的模板中,对于嗅探这种类型的
关于apostrophe-cms - 撇号小部件助手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46722204/