Widget extensions are plugins that supports exposing a static APIs to scripted widget scripts. Documentation for the extensions that are included with Telligent Community can be found at Widget Extensions Documentation.
[toc]
Why should I create a Widget Extension?
Do you have any custom methods or properties you want to be able to call directly from a widget? A custom widget extension can expose these methods and properties so they can be called directly in velocity scripts.
Creating a Widget Extension
First we need a class with one or more public methods or properties that we want to expose in our widget extension. The following class has a single public method named Hello. The method takes a single string parameter name and return "Hello {name}"
public class Sample { public string SayHello(string name) { return "Hello " + name; } }
In order to expose this class we will use a second class that implements the IScriptedContentFragmentExtension Plugin type. First we return an instance of our Sample class to the Extension method.
public object Extension { get { return new Sample(); } }
We also need to provide a unique name for the sample extension. For the example we will use the name "sample_v1".
public object Extension { get { return new Sample(); } }
Once an IScriptedContentFragmentExtension is implemented and deployed to the bin/ folder of a Telligent Community site, it must be enabled within the Administration area before it is available to scripted widgets.
Sample
The completed source code for the sample extension:
using Telligent.Evolution.Extensibility.UI.Version1; namespace Samples { public class Sample { public string SayHello(string name) { return "Hello " + name; } } public class SampleWidgetExtension : IScriptedContentFragmentExtension { #region IScriptedContentFragmentExtension Members public string ExtensionName { get { return "sample_v1"; } } public object Extension { get { return new Sample(); } } #endregion #region IPlugin Members public string Name { get { return "Sample Extension"; } } public string Description { get { return "Enables widgets to use the public members of the Sample class."; } } public void Initialize() { } #endregion } }