How to initialize a widget #222

fredericgrati opened this Issue Mar 8, 2013 · 2 comments


None yet
4 participants

Hi everyone.

I want to find a way to initialize a widget by passing a data object.

Thanks to the video, we can see how we can pass a parameter from the html in order to retrieve it in the widget.

<div data-aura-widget=”navigation” data-aura-nbPage=”28”></div>



Great, but if I have more than only one parameters… Do I have to declare all parameters into the html ?

And if I have a widget in the widget template, do I have to pass the parameter throw the 'parent' widget:

<div data-aura-widget=”toolbar” data-aura-nbPage=”28”></div>

Toolbar Template

<div data-aura-widget=”navigation” data-aura-nbPage=”{{nbPage}}”></div>

Navigation Widget


I probably missed something...
Is it wrong to add an option parameter when we declare a widget with registerWidgetsSource.
In this way, we just have to declare the widget without passing parameters.
Maybe such a method already exists but I didn't find it.

I have another question: where can we post questions about aura? If I don’t propose something different or don’t add new features, I don't know where we can post questions about Aura.
Do you prefer that everyone opens an issue to regroup all questions?
Do you prefer that everyone use the file question of aura drive folder? Or do you prefer to open a google group ?
I found a google group "Aura" but it is empty. :/


sbellity commented Mar 8, 2013

Hi @freuh,

yep for the moment the easiest solution to pass options to a widget is through the data attributes.

Another way to use the options hash is to declare default values for your options in the widget itself (I just merged #212 into master).

You now can declare your widget like that :

  options: {
    nbPage: 30
  initialize: function() { this.html('...') }

You should be able to start widgets the same way we did it in previous aura : by calling this.sandbox.start(list) where list is a array of widgets to start (be to be true, i never used it).

If you have more complex needs, could you provide a more complete example ?

I don't really understand your question about registerWidgetSource... this method is used to declare a new endpoint (or source) to load widgets.

About the google group, (I think) I created it a few weeks ago. But never really used it.
We could use issues for the moment but I guess if the project gets more traffic we will eventually move the discussions somewhere else. In the meantime, I usually am available at #aura on Freenode.


atesgoral commented Mar 9, 2013

If you want to set some global settings for certain widgets, you could also use the per-module configuration feature of RequireJS. Suppose the path of your widget is myWidget.js. You can set some configuration for the widget like this:

    // The usual path, shim etc. configuration
    config: {
        myWidget: {
            foo: 1,
            bar: 2

Then, in your widget, include the special "module" module and access the configuration like this:

define([ "module" ], function (module) {
    var config = module.config();

    // === 1
    // === 2

@addyosmani addyosmani closed this May 4, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment