CMS MADE SIMPLE FORGE

Widgets

 

[#11232] Passing parameters to the Widget

avatar
Created By: Tomas Amsrud (tamsrud)
Date Submitted: 2016-12-06 04:22

Assigned To: Chris Taylor (chrisbt)
Resolution: Accepted
State: Open
Summary:
Passing parameters to the Widget
Detailed Description:
Could it be possible to pass one or more parameters to the module from the pages
where Widgets are used?

Example of use:
On a page I would like to show a menu for a specific subpage.
I would then like to insert the folowing tag on the page:
{Navigator number_of_levels=1 childrenof="products"}
Where "products" will change on different pages.

In the Widget-editor it could be a "parameter" textbox, which would be filled
out like:
Parameter name 1=param-alias1
Page alias=pagealias

On the page when adding a Widget , it would then be added input-fields to the
box.

Then in the Content in the Widget-editor, we could use the code:
{Navigator number_of_levels=1 childrenof=$widget_param['pagealias']}

This would create a very flexible and usefull module.

History

Comments
avatar
Date: 2016-12-06 05:03
Posted By: Chris Taylor (chrisbt)

I am not sure it is necessary to add this functionality into the Widgets module.
Would the following work:

Create a smarty var on the page: {$submenu_parent='some-page-alias'}
Then in the Widget: {Navigator number_of_levels=1 childrenof=$submenu_parent}

Or instead of a smarty var use something like:
{content_module module="ECB2" field="pages" label="Select Submenu Parent Page"
block="submenu_parent"}
      
avatar
Date: 2016-12-06 05:18
Posted By: Tomas Amsrud (tamsrud)

Yes, that would work, but not provide the necessary flexibility. That would
require a new content block for providing the page-alias. But that content block
would still be present, even when the Widget is not activated for that page.

The genius with the Widget-module, is that you can activate a feature for only
selected pages, instead of content-blocks that are only used on a couple of
pages.

Now I can have the widgets: map, contact-persons, sub-menu and selected-sub-menu

With parameters, I could for example add a "category" parameter to
contact-persons (LISE-powered) and a "page-alias" parameter to selected-sub-menu
(Navigation-powered).
      
avatar
Date: 2016-12-06 05:33
Posted By: Tomas Amsrud (tamsrud)

I have site where this feature would be handy, and I just now tried the
{content_module module="ECB2" field="pages" label="Select Submenu Parent Page"
block="submenu_parent"} solution, to see if it works on that specific case.

But on one of the pages, I actually need two {Navigator number_of_levels=1
childrenof=$submenu_parent} tags. So for the solution to work for this case, I
would then have to add two content blocks. Even though the functionality is only
used for 10% of the pages. And still it doesnt cover a case with more than two
blocks.

Today this is solved with a plain text-box where I can past all the needed
smarty-tags. Which is very flexible, but not very userfriendly for the end user.

So by having a parameter to the widget, you could also open for adding the same
widget multiple times to a page, but with different parameter for different
result.

And also ad the flexibility to add more widgets, and then re-arrange them.
      
avatar
Date: 2016-12-06 05:35
Posted By: Chris Taylor (chrisbt)

Ohhhhh, ... I think I get it now. Do you want the option to add more fields
within each Widget?

So for each Widget you would have an extra field/s e.g. 'page-alias' or
'contact-persons-category', etc.

My plan for the next release is to add extra fields, like you can in LISE, News,
Gallery, etc (a limited set of field types).

Does this meet your requirements?

Thanks for the request and comments - appreciated. Chris
      
avatar
Date: 2016-12-06 07:07
Posted By: Tomas Amsrud (tamsrud)

Not exactly.
I want the option to specify parameters for the Widget per use on the page edit.

Another example:
I have two widgets: Map and Contacts
Map could take the parameter "location" and contacts could take the parameter
"category"

On one page I would add the following Widgets in given order:
1. Contacts, and specify category to "sales"
2. Map, and specify location to "London"
3. Another Contacts, and specify category "support"
4. Another Map, and specify location to "Paris"

In the widget I could then make some Smarty-coding for parsing the given
parameters.

Download a PDF with a example of how it could look like here:
https://www.dropbox.com/s/0kckcg4gd1goegm/Widget%20parameters%20function.pdf?dl=0

To make it even more flexible, a parameter could be more than just a input-field
(textarea, dropdown, etc).
But just a simple input-field would expand the module from static content to
dynamic content.

I find the Widget-module very useful, from a user-friendlyness perspective.
Keep up the good work.
      
avatar
Date: 2016-12-06 11:04
Posted By: Chris Taylor (chrisbt)

Thanks for the pdf Tomas. I believe (?) I now understand:

The 'Editor' of a page can add some extra options for the Widget, by adding some
text into a text field, or selecting an item from a dropdown, e.g.
sales,support, ..., London,Paris, ...  That saves having a few or even many
Widgets that are almost identical.

It looks like it would also be useful to be able to optionally select the same
Widget many times, rather than just the once.
      
Updates

Updated: 2016-12-06 11:07
resolution_id: 5 => 6

Updated: 2016-12-06 05:03
resolution_id: => 5