首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何访问data.home._children循环中的自定义字段

如何访问data.home._children循环中的自定义字段
EN

Stack Overflow用户
提问于 2018-06-10 03:45:48
回答 1查看 108关注 0票数 0

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

具体地说,我添加了一个用于摘录的字段、一个封面图像的image Singleton和另一个允许用户定义页面图标的Singleton。

这些图像是这样定义的:

 {
    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图像

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-11 06:26:17

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' ]
      }
    }
  }
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50777917

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档