【问题标题】:How to access custom fields in a data.home._children loop如何访问 data.home._children 循环中的自定义字段
【发布时间】:2018-06-09 19:45:48
【问题描述】:

我在 lib/modules/apostrophe-custom-pages/index.js 中添加了一些自定义字段

具体来说,我为摘录添加了一个字段,为封面图片添加了图像单例,以及另一个允许用户为页面定义图标的单例。

这就是这些图像的定义方式:

 {
    name: 'icon',
    label: 'Icon',
    type: 'singleton',
    widgetType: 'apostrophe-images',
    options:{
        limit: 1,
        minSize: [200,200],
        aspectRatio: [1,1],
    },
    controls:{
      movable:false
    },
    image: true
  },
 {
    name: 'coverimg',
    label: 'Header Image',
    type: 'singleton',
    widgetType: 'apostrophe-images',
    options:{
        limit: 1,
        minSize: [400,400],
        aspectRatio: [1,1],
    },
    controls:{
      movable:false
    },
    image: true
  }

封面图片和我可以在页面上检索的图标使用:{% set coverimage = apos.images.first(data.page.coverimg) or null %}

但是,我无法访问data.home._children 下导航中的图标,如下所示:

    {%- for tab in data.home._children -%}
      {%- set iconImg = apos.images.all(tab.icon) %}
      {{ apos.log(tab) }}
    <li>
      <a class="sidebar-main-link 
      {% if data.page and (apos.pages.isAncestorOf(tab, data.page) or tab._id == data.page._id) %}
        active
      {% endif %}
      " href="{{ tab.slug }}">

        <div class="icon" style="
        backgroung-image: url('{{ apos.attachments.url(image.attachment, { size: 'full'}) }}')  "></div>
        {{ tab.title }}

      </a>
    </li>
  {% endfor %}

这将返回标准 missing.svg 图像

【问题讨论】:

    标签: customization apostrophe-cms


    【解决方案1】:

    There is a new tutorial on the apostrophe documentation site which covers this issue in detail.

    简短的回答是,您必须配置apostrophe-pages 模块的filters 选项来加载相关页面,而不仅仅是非常基本的信息。出于性能原因,这种默认行为并不是一件坏事,但要求 Apostrophe 仅加载一个小部件不会太慢。

    // in lib/modules/apostrophe-pages/index.js
    module.exports = {
      // other configuration, then...
      filters: {
        ancestors: {
          children: {
            areas: [ 'thumbnail' ]
          }
        }
      }
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-12
      • 1970-01-01
      • 1970-01-01
      • 2012-11-03
      • 1970-01-01
      • 1970-01-01
      • 2011-11-08
      相关资源
      最近更新 更多