2017-06-09 31 views
1

我对撇号知之甚少,但我试图创建一个自定义插件。我想在我的小工具三个方面:无法保存图片在插件中插入图案

  1. 标题(字符串)
  2. 描述(字符串)
  3. 一个图像

我还没有找到一种方法来在窗口小部件添加图像作为领域。

现在,我在小部件内部添加了一个单例,它工作正常。但当添加一个图像时,它会显示在页面上,但是当我重新加载页面时,图像不见了。

widget.html代码

<div class="md-jumbotron"> 

<div class="md-grid"> 
    <h1>{{ data.widget.heading }}</h1> 
    <h6>{{ data.widget.desc }}</h6> 

    <div class="img"> 
     {{ apos.singleton(data.page, 'jumbotroPic', 'apostrophe-images', { 
      limit: 1, 
      size: 'full' 

     }) }} 
    </div> 
</div> 

我得到了在控制台下面

$ node app.js 

WARNING: No session secret provided, please set the `secret` property of the 
`session` property of the apostrophe-express module in app.js 
WARNING: widget type text exists in content but is not configured 
WARNING: widget type text exists in content but is not configured 
I see no data/address file, defaulting to address 0.0.0.0 
I see no data/port file, defaulting to port 3000 
Listening on 0.0.0.0:3000 
WARNING: widget type text exists in content but is not configured 
WARNING: widget type text exists in content but is not configured 
WARNING: widget type text exists in content but is not configured 
WARNING: widget type text exists in content but is not configured 

我的窗口小部件的JavaScript代码是:

module.exports = { 
    extend: 'apostrophe-widgets', 
    label: 'Jumbotron', 
    addFields: [ 
    { 
     name: 'heading', 
     type: 'string', 
     label: 'Heading', 
     required: true 
    }, 
    { 
     name: 'desc', 
     type: 'string', 
     label: 'Description', 
     required: true 
    } 
    ], 
    construct: function(self, options) { 
    var superPushAssets = self.pushAssets; 
    self.pushAssets = function() { 
     superPushAssets(); 
     self.pushAsset('stylesheet', 'jumbotron', { when: 'always' }); 
    }; 
    } 
}; 

回答

2

您可以将图像控件添加到您的widget的模式是这样

{ 
    name: 'image', 
    label: 'Jumbo Image', 
    type: 'singleton', 
    widgetType: 'apostrophe-images', 
    options: { 
    limit: 1, 
    } 
} 

只是坚持在addFields阵列。

感谢您试用Apostrophe!

0

确定这里我找到了完整的解决方案:

这里是我的插件架构:

module.exports = { 
    extend: 'apostrophe-widgets', 
    label: 'Jumbotron', 
    addFields: [ 
    { 
     name: 'heading', 
     type: 'string', 
     label: 'Heading', 
     required: true 
    }, 
    { 
     name: 'desc', 
     type: 'string', 
     label: 'Description', 
     required: true 
    }, 
    { 
     name: 'image', 
     label: 'Jumbo Image', 
     type: 'singleton', 
     widgetType: 'apostrophe-images', 
     options: { 
     limit: 1, 
     } 
    } 
    ], 
    construct: function(self, options) { 
    var superPushAssets = self.pushAssets; 
    self.pushAssets = function() { 
     superPushAssets(); 
     self.pushAsset('stylesheet', 'jumbotron', { when: 'always' }); 
    }; 
    } 
}; 

这里是我的小部件的HTML代码

<div class="md-jumbotron"> 

    <div class="md-grid"> 
     <h1> 
     {{ data.widget.heading }} 
     </h1> 
     <h6> 
     {{ data.widget.desc }} 
     </h6> 

     <div class="img"> 
      {{ 
       apos.singleton(
        data.widget, 
        'image', 
        'apostrophe-images', 
        { 
         edit: false 
        } 
       ) 
      }} 
     </div> 
    </div> 
</div> 

取自HTML代码here