我一直在使用Apostrophe CMS,它很棒。我想做的是在页面上预定义小部件,而无需用户添加这些小部件,并使这些小部件具有占位符数据。例如,我希望撇号图像已经在区域中的页面上并具有占位符图像。然后,用户将更改内容以满足他们的需求。那可能吗?
从数据库中的预填充属性复制JSON,就像Apostrophe会存储它一样(db.aposDocs.find({slug: '/sample'}
或其他)。
在lib/modules/apostrophe-pages/index.js
module.exports = {
types: [
{
name: 'default',
label: 'Default'
}
// .. other page types
],
construct: function(self, options) {
self.beforeInsert = function(req, page, options, callback) {
////////////
// Should i pre populate this new page with sample data?
if (page.type === 'default') {
page.body = {
"type" : "area",
"items" : [
{
"by" : "id",
"_id" : "w388717969570838460",
"pieceIds" : [
"ck2z5b8y0002xs6q7jcthp2ds"
],
"relationships" : {
"ck2z5b8y0002xs6q7jcthp2ds" : {
"left" : null,
"top" : null,
"width" : null,
"height" : null,
"x" : null,
"y" : null
}
},
"type" : "apostrophe-images"
},
{
"_id" : "w859631071931278751",
"type" : "apostrophe-rich-text",
"content" : "<p><strong><em>Authors often misinterpret the mom as a surest quilt, when in actuality it feels more like a rimless jeep. Far from the truth, an iffy russia without porcupines is truly a sycamore of jessant farmers.</em></strong></p>\n\n<p> </p>\n"
}
]
}
}
return setImmediate(callback);
};
}
};
这将使用包含body
小部件和apostrophe-images
小部件的区域来预先填充页面的apostrophe-rich-text
属性。
您可以通过在您感兴趣的页面类型上添加一个字段来进一步限制此行为,该字段允许编辑者选择退出此行为并在beforeInsert
条件下对其进行检查。同样,此示例有点僵化,因为您将图像ID硬编码到
beforeInsert
中。您可以通过运行带有特定标签(“样本”)的图像查询,生成lorem ipsum文本来进一步获得幻想并在添加属性之前使用外部模块等。