Reg dynamic generation of widgets via code

(piwikdev) #1

Our requirement is to display n number of charts in each widget based on the a number that we get in query parameter. Also each chart will be unique based on the backend data.

No other widgets than widget of our interest should be displayed in the screen

We are aware Add_widget function is available, but we are unsure where to place the code what are the files we need to write etc

Please help us in this regard. We are completely new to Piwik style_emoticons/<#EMO_DIR#>/rolleyes.gif


(vipsoft) #2

You’ll need to create a new plugin.

You should look at the examples in the plugins/ folder.

(piwikdev) #3

Thanks for the reply.
I have followed the same way to add a widget.

My requirement here is, if I have an array of 10 values then I want to create ten widgets depending on the array value.As per my understanding, for every widget we have to write a different method in a controller.

I want to write a single controller with single method, which will add all the ten widget. I have tried to add the 10 widget with the help of for loop. It is registering as 10 different widget but while adding on dashboard it is adding only a single widget.

It is feasible in Piwik or not?


(vipsoft) #4

you want to create up to 10 widgets, but add them to the dashboard with a single step? I don’t think Piwik wasn’t designed with use case in mind… feel free to propose a hook if there isn’t already one.

Adding too many widgets to the Dashboard sort of defeats the idea behind a dashboard. You might consider creating a new page to host all the widgets. (See Piwik_AddMenu and Smarty templates). And let the user pick and choose for the Dashboard.

(piwikdev) #5

Thanks for the reply
As per suggestion we might move for new page construction.
I will elaborate on the requirement

  1. we will get n number of values in request parameter
    2)Depending on the number of request parameter values we need to construct that many number of widgets i.e if we get 4 values in request parameter we need to construct 4 widgets in the page
    3)What each widgets will house depends on the value in each request parameter(based on the value in request param, each widget has to query the db and construct line dig/bar charts). This would imply each widget needs seperate function or controller to display the contents(chart/line dig)

So this requirement would demand dynamic construction of widgets capable of displaying differnet data. Before runtime, there is no way that we can decide upon the number of controllers or methods inside controllers, for us to tie them to widgets (because the number of widgets and data to be displayed depends on request parameter)

Also we are displaying piwik data in another application using iframe include. So user will not have control to add widgets (also requirement demands user not to do so). Dynamic construction and display of widgets is what we are eyeing at.Please let us know if Piwik_AddMenu and Smarty templates, will help our cause. More pointers would really be handy for us since we new and trying stuff for the first time


(vipsoft) #6

As I understand it, you should be able to accomplish this.

To see this in action, see how the dashboard is loaded dynamically.…;date=yesterday

(Jiten007) #7


I have also the similar problem.

Regarding the link you have given, its generating the dynamic widgets but how it is generating ?
I am not getting the idea behind it. Can you suggest me the corresponding files in which i should look?