<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Widget Contexts</title><link>https://community.telligent.com/community/11/w/developer-training/65064/widget-contexts</link><description /><dc:language>en-US</dc:language><generator>14.0.0.586 14</generator><item><title>Widget Contexts</title><link>https://community.telligent.com/community/11/w/developer-training/65064/widget-contexts</link><pubDate>Wed, 05 Aug 2020 15:03:31 GMT</pubDate><guid isPermaLink="false">756d85ff-f5a4-440a-b319-401e7c786344</guid><dc:creator>Former Member</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65064/widget-contexts#comments</comments><description>Current Revision posted to Developer Training by Former Member on 08/05/2020 15:03:31&lt;br /&gt;
&lt;p&gt;Widgets define the context they require to render. &amp;nbsp;For example, the Blog - Post widget always displays the current contextual blog post. &amp;nbsp;It is dependent on having a blog post available to render. &amp;nbsp;The Blog - Post widget, therefore, defines &amp;quot;Blog Post&amp;quot; as a required context.&lt;/p&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;h2&gt;&lt;a id="Why_Should_You_Use_Widget_Contexts" name="Why_Should_You_Use_Widget_Contexts"&gt;&lt;/a&gt;Why Should You Use Widget Contexts&lt;/h2&gt;
&lt;p&gt;Whether you are creating a new application or adding widgets to existing applications, it is important to use widget contexts. &amp;nbsp;If your&amp;nbsp;widgets require certain items to be in context to function properly, widget contexts allow you to enforce this logic and prevent end users from adding widgets to pages where they would not function.&lt;/p&gt;
&lt;h2&gt;&lt;a id="Creating_a_Widget_Context_Provider" name="Creating_a_Widget_Context_Provider"&gt;&lt;/a&gt;Creating a Widget&amp;nbsp;Context Provider&lt;/h2&gt;
&lt;p&gt;To add a widget context, implement the&amp;nbsp;&lt;a title="IScriptedContentFragmentContextProvider-based plugins" href="/developers/w/developer90/50320.iscriptedcontentfragmentcontextprovider-plugin-type"&gt;IScriptedContentFragmentContextProvider&lt;/a&gt;&amp;nbsp;interface (which requires a reference to Telligent.Evolution.ScriptedContentFragments.dll). The IScriptedContentFragmentContextProvider&amp;nbsp;interface extends &lt;a class="ExistingPageLink" title="Click to view the page titled: Plugins" href="/training/w/developer90/52443.plugins"&gt;IPlugin&lt;/a&gt;&amp;nbsp;to add support for widget context providers.&lt;/p&gt;
&lt;p&gt;First we need to&amp;nbsp;identify which contexts we are defining. &amp;nbsp;This method should return all contexts managed by this context provider. &amp;nbsp;Each ContextItem is defined using a Name and an Id. &amp;nbsp;The Name is shown in the widget editing user interface and the Id is used internally to identify this context. &amp;nbsp;In our sample we will define a single widget context with a name&amp;nbsp;&amp;quot;Blog Example&amp;quot;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;IEnumerable&amp;lt;ContextItem&amp;gt; IScriptedContentFragmentContextProvider.GetSupportedContextItems()
{
    return new List&amp;lt;ContextItem&amp;gt;()
    {
        new ContextItem(&amp;quot;Blog Example&amp;quot;, BlogExampleContextItemId)
    };
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Next we implement the HasContextItem method. &amp;nbsp;This method should return true if the provided context identifier exists on the provided page. &amp;nbsp;For unrecognized context identifiers, the provider should always return false. &amp;nbsp;For recognized context identifiers, the provider should only return true if a recognized and valid object described by the context exists on the page. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;bool IScriptedContentFragmentContextProvider.HasContextItem(System.Web.UI.Page page, Guid contextItemId)
{
    return contextItemId == BlogExampleContextItemId &amp;amp;&amp;amp; PublicApi.Url.CurrentContext != null &amp;amp;&amp;amp;
        PublicApi.Url.CurrentContext.ContextItems.GetAllContextItems()
            .Any(item =&amp;gt; item.ContentTypeId == PublicApi.Blogs.ApplicationTypeId);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here is the completed source code for our widget context provider:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://community.telligent.com/cfs-file/__key/communityserver-wikis-components-files/00-00-00-12-83/6242_2E00_BlogExampleWidgetContext_2E00_cs"&gt;community.telligent.com/.../6242_2E00_BlogExampleWidgetContext_2E00_cs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Once this sample is deployed to Verint Community and the plugin has been enabled, you will be able to select the context provider when developing a widget in Widget Studio.&lt;/p&gt;
&lt;p&gt;&lt;a href="/cfs-file/__key/communityserver-wikis-components-files/00-00-00-12-83/3704.png"&gt;&lt;img alt=" " src="/resized-image/__size/550x240/__key/communityserver-wikis-components-files/00-00-00-12-83/3704.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;When laying out&amp;nbsp;a page in the site, any widget that requires the &amp;quot;Blog Example&amp;quot; context will only be available to add to pages where a blog is in context.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: IScriptedContentFragmentContextProvider&lt;/div&gt;
</description></item><item><title>Widget Contexts</title><link>https://community.telligent.com/community/11/w/developer-training/65064/widget-contexts/revision/1</link><pubDate>Thu, 13 Jun 2019 19:24:04 GMT</pubDate><guid isPermaLink="false">756d85ff-f5a4-440a-b319-401e7c786344</guid><dc:creator>Ben Tiedt</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65064/widget-contexts#comments</comments><description>Revision 1 posted to Developer Training by Ben Tiedt on 06/13/2019 19:24:04&lt;br /&gt;
&lt;p&gt;Widgets define the context they require to render. &amp;nbsp;For example, the Blog - Post widget always displays the current contextual blog post. &amp;nbsp;It is dependent on having a blog post available to render. &amp;nbsp;The Blog - Post widget, therefore, defines &amp;quot;Blog Post&amp;quot; as a required context.&lt;/p&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;h2&gt;&lt;a id="Why_Should_You_Use_Widget_Contexts" name="Why_Should_You_Use_Widget_Contexts"&gt;&lt;/a&gt;Why Should You Use Widget Contexts&lt;/h2&gt;
&lt;p&gt;Whether you are creating a new application or adding widgets to existing applications, it is important to use widget contexts. &amp;nbsp;If your&amp;nbsp;widgets require certain items to be in context to function properly, widget contexts allow you to enforce this logic and prevent end users from adding widgets to pages where they would not function.&lt;/p&gt;
&lt;h2&gt;&lt;a id="Creating_a_Widget_Context_Provider" name="Creating_a_Widget_Context_Provider"&gt;&lt;/a&gt;Creating a Widget&amp;nbsp;Context Provider&lt;/h2&gt;
&lt;p&gt;To add a widget context, implement the&amp;nbsp;&lt;a title="IScriptedContentFragmentContextProvider-based plugins" href="/developers/w/developer90/50320.iscriptedcontentfragmentcontextprovider-plugin-type"&gt;IScriptedContentFragmentContextProvider&lt;/a&gt;&amp;nbsp;interface (which requires a reference to Telligent.Evolution.ScriptedContentFragments.dll). The IScriptedContentFragmentContextProvider&amp;nbsp;interface extends &lt;a class="ExistingPageLink" title="Click to view the page titled: Plugins" href="/training/w/developer90/52443.plugins"&gt;IPlugin&lt;/a&gt;&amp;nbsp;to add support for widget context providers.&lt;/p&gt;
&lt;p&gt;First we need to&amp;nbsp;identify which contexts we are defining. &amp;nbsp;This method should return all contexts managed by this context provider. &amp;nbsp;Each ContextItem is defined using a Name and an Id. &amp;nbsp;The Name is shown in the widget editing user interface and the Id is used internally to identify this context. &amp;nbsp;In our sample we will define a single widget context with a name&amp;nbsp;&amp;quot;Blog Example&amp;quot;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;IEnumerable&amp;lt;ContextItem&amp;gt; IScriptedContentFragmentContextProvider.GetSupportedContextItems()
{
    return new List&amp;lt;ContextItem&amp;gt;()
    {
        new ContextItem(&amp;quot;Blog Example&amp;quot;, BlogExampleContextItemId)
    };
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Next we implement the HasContextItem method. &amp;nbsp;This method should return true if the provided context identifier exists on the provided page. &amp;nbsp;For unrecognized context identifiers, the provider should always return false. &amp;nbsp;For recognized context identifiers, the provider should only return true if a recognized and valid object described by the context exists on the page. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;bool IScriptedContentFragmentContextProvider.HasContextItem(System.Web.UI.Page page, Guid contextItemId)
{
    return contextItemId == BlogExampleContextItemId &amp;amp;&amp;amp; PublicApi.Url.CurrentContext != null &amp;amp;&amp;amp;
        PublicApi.Url.CurrentContext.ContextItems.GetAllContextItems()
            .Any(item =&amp;gt; item.ContentTypeId == PublicApi.Blogs.ApplicationTypeId);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here is the completed source code for our widget context provider:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://community.telligent.com/cfs-file/__key/communityserver-wikis-components-files/00-00-00-12-83/6242_2E00_BlogExampleWidgetContext_2E00_cs"&gt;community.telligent.com/.../6242_2E00_BlogExampleWidgetContext_2E00_cs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Once this sample is deployed to Telligent Community and the plugin has been enabled, you will be able to select the context provider when developing a widget in Widget Studio.&lt;/p&gt;
&lt;p&gt;&lt;a href="/cfs-file/__key/communityserver-wikis-components-files/00-00-00-12-83/3704.png"&gt;&lt;img src="/resized-image/__size/550x240/__key/communityserver-wikis-components-files/00-00-00-12-83/3704.png" alt=" " /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;When laying out&amp;nbsp;a page in the site, any widget that requires the &amp;quot;Blog Example&amp;quot; context will only be available to add to pages where a blog is in context.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: IScriptedContentFragmentContextProvider&lt;/div&gt;
</description></item></channel></rss>