- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 06:07 AM
I have a widget that has an option, called "message". In one place, I have embedded this widget in another widget. I have created an option called "message" on the parent widget.
How do i link the parent widget's option to the embedded widget?
The solution is this:
function(spUtil) { /* widget controller */
var c = this;
spUtil.get("custom-search-page", {message: c.options.message}).then(function(response) {
c.data.parentMessage = response.options.incident_message;
c.data.parentMessageFlag = 'true';
});
}
I'm not positive i understand exactly what is happening, but it's behaving the way i want it to.
The widget im using is embedded sometimes, and not at other times. The widget is a button with a string of text above it. I set the value of that string with instance options. I wanted to be able to set that text even when it's embedded in this widget.
from what i understand, the SPutil gets the message i ask for from the widget i specify, and returns a promise. When the promise comes back, i set a data paramenter to equal the response field, and set a flag to true.
in my server script i check to see if the flag is true. if it is, I display the parent message. otherwise i use the one local to the widget.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2017 06:12 PM
You can use the following in your server script:
data.widget = $sp.getWidget("widget-id", options);
The second parameter is the object being passed in to the widget, so this should pass all available "options" on the first widget in to the embedded widget. I haven't tested this, but 99% certain it'll work.
And then all you have to do is display the widget in your HTML:
<sp-widget widget="data.widget"></sp-widget>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2017 09:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2017 04:47 PM
Hi Nathan,
So to clarify in your server script:
- this is being run in the first/parent widget:
data.widget = $sp.getWidget("widget-id", options); - "widget-id" is referring to the embedded widget
- options are the instance options object already passed to the parent widget
Is that all correct?
Thanks,
-Brian
Edit: Ha.... when I'd started there were no other replies (yet) to your comment. I got side-tracked and didn't reload the thread. Already answered
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2017 07:24 AM
Hello Nathan,
How would you execute a widget if the widget does not have options? For example, the OOB widget "Catalog Content" is trying to get info from the current portal SC catalog. I am trying to execute with you method but it does not seem to work. Any information would be appreciated. Thanks!
