I'm having difficulty displaying an image uploaded via an Apostrophe widget. Specifically I'm creating a 'hero' widget with a background image, title and description text over the top of the image. The widget seems to be working correctly as I can add title and description text in, but the image does not display. The error I am seeing in the command line is:
'Template warning: Impossible to retrieve the attachment url since it is missing, a default icon has been set. Please fix this ASAP!'
index.js for the widget:
module.exports = {
extend: 'apostrophe-widgets',
name: 'heroimage',
label: 'Hero Image',
addFields: [
{
name: 'hero-image',
label: 'Hero Image',
type: 'attachment',
widgetType: 'apostrophe-images',
required: true,
extensions: [ 'jpg', 'png' ],
extensionMaps: {
jpeg: 'jpg'
},
// uploadfs should treat this as an image and create scaled versions
image: true,
options: {
minSize: [ 1280, 900 ],
limit: 1,
}
},
{
name: 'hero-title',
label: 'Hero Title',
type: 'area',
options: {
widgets: {
'apostrophe-rich-text': {
controls: [ 'Bold', 'Italic', 'Link', 'Unlink' ]
}
}
}
},
{
name: 'hero-description',
label: 'Hero Description',
type: 'area',
options: {
widgets: {
'apostrophe-rich-text': {
controls: [ 'Bold', 'Italic', 'Link', 'Unlink' ]
}
}
}
}
]
};
widget.html:
<div class="hero align-center-middle text-center"
style="background: url('{{ apos.attachments.url(image.attachment) }}'); background-size:cover; background-position:center;">
<div class="grid-x grid-padding-x">
<div class="cell">
<h1>
{{ apos.area(data.widget, 'hero-title') }}
</h1>
</div>
<div class="cell">
<p>
{{ apos.area(data.widget, 'hero-description') }}
</p>
</div>
</div>
</div>
I've tried every combination of code inside the '{{ apos.attachments.url(image.attachment) }}' but nothing seems to work. Have I done this correctly, is there something I am missing? Any help is greatly appreciated.
Thanks, Jon
image
a nunjucks variable your creating elsewhere? Hard to tell from your snippet. My first thought is that you should passdata.widget.hero-image
to the url helper. Try logging the data your passing to the helpers like{{ apos.log(image) }}
to make sure you have something at all. – Stuart Romanek