1

我正在努力在 Apsotrophe CMS 上展示一些内容。

我正在使用apostrophe-pieces创建描述字段:

{
  name: 'description',
  label: 'Description',
  type: 'singleton',
  widgetType: 'apostrophe-rich-text',
  options: {
    toolbar: [ 'Bold', 'Italic', 'Link', 'Unlink' ]
  }
}

我希望它显示在自定义页面的 index.html 视图中。

但是,使用{{ apos.singleton(data.piece, 'description', 'apostrophe-rich-text') }}会引发错误并且无法呈现页面。它只适用于show.html

/lib/modules/basics-pages/views/index.html,我的代码是:

{% extends "apostrophe-pages:outerLayoutBase.html" %}

{% block content %}
  <div class="basics-grid">
    {% for piece in data.pieces %}
      <article>
        <h4>{{ piece.title }}</h4>
        {% set image = apos.images.first(piece.icon) %}
        {% if image %}
          <img src="{{ apos.attachments.url(image, { size: 'one-sixth' }) }}" />
        {% endif %}
        <div class="desc">
        {{ apos.singleton(data.piece, 'description', 'apostrophe-rich-text') }}
        </div>
      </article>
    {% endfor %}
  </div>
{% endblock %}

有人可以帮助我使用正确的代码来显示单例小部件的内容吗?

4

1 回答 1

1

您可能知道,我是 P'unk Avenue 的 Apostrophe 的首席开发人员。

这段代码:

{% for piece in data.pieces %}

表示您有一个名为 的循环变量piece。那正是你想要的。

这段代码:

{{ apos.singleton(data.piece, 'description', 'apostrophe-rich-text') }}

查找piece作为属性data并忽略您的循环变量。

删除data.,你应该很高兴。

您需要添加:

{{ apos.singleton(piece, 'description', 'apostrophe-rich-text', { edit: false }) }}

避免在索引页面上进行内联编辑,这会更令人困惑而不是有用。

于 2016-12-20T21:57:17.080 回答