Lets say we created a simple widget which may have a string or a richtext field. When I insert the widget into the html, I would like to specify which field to be visible/active. In other words I'd like to add some custom options to the widget, which will change its behavior. The widget looks like this:
{{
apos.singleton(data.page, 'footerTitle', 'footerTitle', {
controls: {
movable: false,
position: 'top-right'
}
})
}}
And I'd like to do something like this:
{{
apos.singleton(data.page, 'footerTitle', 'footerTitle', {
controls: {
movable: false,
position: 'top-right'
},
settings: {
type: 'string',
anotherParameter: 1,
thirdParameter: false
}
})
}}
Later (inside the widget's index.js) these parameters to be handled accordingly:
...
beforeConstruct: function( self, options )
{
if (type === 'string')
{
// Do some additional setup, magic, whatever...
}
switch (anotherParamter)
{
// Add some insane code here :)
}
},
construct: function( self, options )
{
const superLoad = self.load;
self.load = ( req, widgets, callback ) => superLoad( req, widgets, ( err ) =>
{
if( err )
{
return callback( err );
}
for( const widget of widgets )
{
// Some additional work here based on the initial settings.
}
return callback( null );
} );
}
...
Is there any possibility to add custom parameters, options to a widget (in version 2.98.1 or later in 3.0.0)?