1

I have a custom widget:

module.exports = {
    extend: 'apostrophe-widgets',
    label: 'Banner',
    addFields: [
      {
        name: 'bannerImg',
        type: 'attachment',
        label: 'Picture',
        def: 'http://via.placeholder.com/350x150'
      }
    ]
  };

And widget view:

<img class="logo" src="{{ apos.attachments.url(data.widget.bannerImg) }}" />

If I load image It's Ok I see it. But I don't have the default value. Also can I choose file from gallery without upload?

zemil
  • 3,235
  • 2
  • 24
  • 33
  • in official documentation I haven't found any information about defaults value. Also I have a problem with singleton type widget def value – zemil Jul 10 '18 at 14:19

1 Answers1

1

I spent a half of the day and found the solution:

as answered in: How to define widgets with default values in Apostrophe CMS

 {% if apos.areas.isEmpty(data.widget, 'bannerImg') %}
      <h1>Default Value</h1>
 {% endif %}
 {{ apos.singleton(data.widget, 'bannerImg', 'apostrophe-images', { limit: 1 }) }} 

And also if we want to get href of this images:

{{ apos.attachments.url(apos.images.first(data.widget.bannerImg)) }}

Also in index.js I changed on:

  {
    name: 'bannerImg',
    type: 'singleton',
    label: 'Banner',
    widgetType: 'apostrophe-images',
    options: {
      limit: 1
    }
  },
zemil
  • 3,235
  • 2
  • 24
  • 33