这是以下问题的部分延续:如何将片段显示为另一个片段?还有一个我不小心删除的,但得到了很多帮助(谢谢!)
我有以下模块 blogTag,我想通过该joinByOneReverse
字段将撇号博客模块的片段以及我“工作”和“灵感”创建的片段连接起来。它在这里 index.js:
module.exports = {
extend: 'apostrophe-pieces',
name: 'blogTag',
label: 'Blog Tag',
pluralLabel: 'Blog Tags',
addFields: [
{
name: 'title',
label: 'Title',
type: 'string',
required: true
},
{
name: 'intro',
label: 'Introduction',
type: 'area',
options: {
widgets: {
'apostrophe-rich-text': {
controls: ['Bold', 'Italic', 'Link', 'Unlink']
},
'apostrophe-images': {}
}
}
},
{
name: 'icon',
label: 'Icon',
type: 'singleton',
widgetType: 'apostrophe-images',
options: {
limit: 1
}
},
{
name: '_workName',
type: 'joinByOneReverse',
withType: 'work',
label: 'Work',
idField: 'blogTagId',
filters: {
projection: {
title: 1,
slug: 1,
type: 1,
tags: 1
}
}
},
{
name: '_inspirationName',
type: 'joinByOneReverse',
withType: 'inspiration',
label: 'Inspiration',
idField: 'blogTagInspirationId',
filters: {
projection: {
title: 1,
slug: 1,
type: 1,
tags: 1
}
}
},
{
name: '_blogTagArticleName',
type: 'joinByOneReverse',
withType: 'apostrophe-blog',
label: 'Blog Article',
idField: 'blogTagArticleId',
filters: {
projection: {
title: 1,
slug: 1,
type: 1,
tags: 1
}
}
}
]
}
作为“工作”部分的示例,我在“b2b-portfolio”文件夹中有以下模块和以下 index.js 模块:
module.exports = {
extend: 'apostrophe-pieces',
name: 'work',
label: 'Work',
pluralLabel: 'Works',
addFields: [
{
name: 'title',
label: 'Title',
type: 'string',
required: true
},
{
name: 'intro',
label: 'Introduction',
type: 'area',
options: {
widgets: {
'apostrophe-rich-text': {
controls: ['Bold', 'Italic', 'Link', 'Unlink']
},
'apostrophe-images': {}
}
}
},
{
name: 'screenshot',
label: 'Screenshot',
type: 'singleton',
widgetType: 'apostrophe-images',
options: {
limit: 1,
minSize: [ 800, 800 ],
aspectRatio: [ 1, 1]
}
},
{
name: '_blogTag',
type: 'joinByOne',
withType: 'blogTag',
label: 'Blog Tag',
idField: 'blogTagId',
filters: {
projection: {
title: 1,
slug: 1,
type: 1,
tags: 1
}
}
},
{
name: 'publishedAt',
label: 'Publishing date',
type: 'date'
}
]
}
但是,在模块“b2b-blog-tags-pages”中,show.html 视图中的以下内容不会输出预期数据:
{% for work in data._workName %}
<h2><a href="{{ work._url }}">{{ work.title }}</a></h2>
{% endfor %}
我在这里错过了什么或做错了什么?
编辑:以下也不起作用:
{% for work in data.piece._workName %}
<h2><a href="{{ work._url }}">{{ work.title }}</a></h2>
{% endfor %}
以下是以 aposDocs 集合中的 MongoDB 文档为例:
和..