![](/img/trans.png)
[英]Apostrophe CMS propagating edit:false of area to all children widgets and pieces
[英]Apostrophe-cms cloning a pieces area into another non pieces area
我有一個名為模板的 apos 片段集合,在該模式中,我有一個用於其他小部件等的 apos 區域。
我已經創建了一個標准的非碎片小部件,它帶有一個可以選擇區域的 joinbyone,但我似乎找不到將碎片區域中的項目克隆到小部件中的非碎片區域的方法。
我的想法是我可以將模板創建為片段,當它們被選中時,我將該模板的副本創建到匿名區域中,因此片段區域保持不變。 任何幫助將不勝感激
小部件沒有自己的afterSave
類型事件處理程序,因為保存的並不是真正的它們。 這是他們所屬的文件。 您可以在 doc 類型上使用afterSave
事件處理程序:
步驟 3b 實際上是更新復制區域中所有小部件的_id
屬性。 區域小部件在移動或復制時具有唯一的_ids
,因此應該為這個新上下文新生成這些小部件。 cuid
實用程序對此很有用。
這是一個不尋常的案例,但它肯定很有趣。 如果你需要這樣做,我認為這可能會起作用。 它使數據保持正確,而不是在模板中進行數據工作。
我似乎無法在數據服務器端處理,所以我使用模板助手將數據重新發布,然后從片段中復制區域並通過重新點路徑/docid 例程運行項目。 到目前為止,這是一種享受!
模板.html
{% import "macros/widgets.html" as widget %}
{%if data.widget%}
{% set section=apos.sectionTemplate.copyme(data.widget) %}
{%endif%}
{{ widget.postWidget(section, 'newnsection') }}
小部件.js
const apos = require("apostrophe");
module.exports = {
extend: 'apostrophe-widgets',
label: 'Section Template',
alias: 'sectionTemplate',
defer: true,
addFields: [
{
name: '_nsection',
type: 'joinByOne',
withType: 'templateSections',
label: 'Template',
required: true,
idField: 'id',
filters: {
projection: {
title: 1,
nsection: 1
}
}
}
,
{
name: 'newnsection',
type: 'area',
label: 'Section',
contextual: true,
def: ''
}
],
construct: function (self, options) {
self.addHelpers({
copyme: function (data) {
if (data.newnsection.items.length == 0) {
data.newnsection.items = data._nsection.nsection.items
area = recalcDotPathsAreas(data.newnsection);
function recalcDotPathsAreas(area) {
var docId = area._docId;
var dotPath = area._dotPath;
area.items.forEach(stlevel);
function stlevel(value, index, array) {
var widgetDotPath = dotPath + '.items.' + index;
try {
var $widget = value;
value.__docId = docId;
value.__dotPath = widgetDotPath;
recalcDotPathsAreasWidget(value, docId, widgetDotPath);
} catch (e) {
}
};
return area
};
function recalcDotPathsAreasWidget($widget, docId, dotPath) {
$widget.items.forEach(sclevel);
function sclevel(value, index, array) {
var $area = value;
var areaDocId = value._id;
if ((areaDocId !== docId) && areaDocId && (areaDocId.substring(0, 1) === 'w')) {
value._id = docId;
areaDocId = docId;
}
if (areaDocId === docId) {
var areaDotPath = value._dotPath;
if (areaDotPath) {
var components = areaDotPath.split('.');
var name = components.pop();
value._dotPath = dotPath + '.' + name;
recalculateDotPathsInArea(value);
}
}
};
};
}
return data;
}
});
var superPushAssets = self.pushAssets
self.pushAssets = function () {
superPushAssets()
// self.pushAsset('stylesheet', 'smart-section', {when: 'always'})
self.pushAsset('script', 'always', { when: 'always' })
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.