Apostrophe cms 如何在撇号CMS中从宏定义区域小部件

Apostrophe cms 如何在撇号CMS中从宏定义区域小部件,apostrophe-cms,Apostrophe Cms,我想在一个地方为我的所有列和布局定义小部件 此代码将位于views/macros/columnWidgets.html中 {% macro columnWidgets(data, option) %} {{ apos.area(data.widget, '{{option}}', { blockLevelControls: true, widgets: { 'apostrophe-rich-text': { toolbar: [ 'Styles', 'Bold', 'Italic', '

我想在一个地方为我的所有列和布局定义小部件

此代码将位于views/macros/columnWidgets.html中

 {% macro columnWidgets(data, option) %}
{{ apos.area(data.widget, '{{option}}', {
blockLevelControls: true,
widgets: {
'apostrophe-rich-text': {
   toolbar: [ 'Styles', 'Bold', 'Italic', 'Blockquote', 'Link', 'Anchor', 'Unlink', 'BulletedList' ],
   styles: [
    { name: 'Paragraph',  element: 'p'  },
    { name: 'Quote / Section Descriptor', element: 'h3' },
    { name: 'Main Heading', element: 'h1',attributes: { 'class': 'main-heading'}  }
   ]
 },
 'apostrophe-html': {
   toolbar: [ 'Styles', 'Bold', 'Italic', 'Link', 'Unlink', 'Anchor', 'Table', 'BulletedList', 'Blockquote', 'Strike', 'Subscript',  'Superscript','Image','slideshow' ],
   styles: [
     { name: 'Marker: Yellow', element: 'span', styles: { 'background-color': 'Yellow' } }
   ]
 },
 'apostrophe-images': {
   minSize: [ 700, 350 ],
   aspectRatio: [ 2, 1 ],
   size: 'full'
 }
}
}) }}
{% endmacro %}
然后在我的4ColumnLayout小部件中,我将包括一些类似于这些内容的内容

{%import'macros/columnWidgets.html'作为columnWidgets%}


{{apps.columnWidgets(data,'column1')}

当然,我们在自己的项目中总是这样做

// in app.js

modules: {
  'apostrophe-templates': {
    viewsFolderFallback: __dirname + '/views'
  }, ...
}

{# In views/macros/areas.html %}

{% macro content(context, name) %}
  {{ apos.area(context, name, {
    widgets: {
      'apostrophe-rich-text': {
        toolbar: [ 'Styles', 'Bold', 'Italic', 'Link', 'Anchor', 'Unlink', 'BulletedList' ]
      },
      'apostrophe-images': {},
      'apostrophe-files': {},
      'apostrophe-video': {}
    }
  }) }}
{% endmacro %}

{# In any other template in any module #}

{% import "macros/areas.html" as areas %}
{{ areas.content(data.page, 'body') }}
使用
viewsFolderFallback
对于允许
共享顶级文件夹,作为从任何模块导入、包含、扩展等模板文件的备用位置。

我收到一个错误:侦听e.stack:template render error:(column-2-widgets:widget.html)错误:模板名称必须是字符串:NaN at Object.exports.prettifyError(/Users/woodbr/projects/earlham/node_modules/nunjucks/src/lib.js:34:15)在/Users/woodbr/projects/earlham/node_modules/nunjucks/src/environment.js:486:31看起来nunjucks与宏模板名称有问题必须是字符串:NaNSorry,我在导入调用中留下了引号,请尝试使用该修复。谢谢,成功了。我使用的模式是全宽/窄宽布局,然后在每个f那些具有1、2、3或4列选项。这样,在常规页面上,您可以在topI get
错误处拥有一个全宽的hero小部件:render()不能从嵌套在另一个render()调用中的Nunjucks辅助函数调用。请改为使用partial()。
随机。此错误很少发生