More in this section

Forums / Developing with Sitefinity / Multiple custom Modules - one result

Multiple custom Modules - one result

6 posts, 0 answered
  1. Owain
    Owain avatar
    110 posts
    Registered:
    17 Jan 2012
    23 Apr 2012
    Link to this post
    Is it possible to create multiple modules with information but on the front end pull all that data in to one widget? i.e.
    A location module which just has map information
    A contact module which has contact details but some locations will be using the same contact info.

    Im looking to use the modules like database tables and join them rather than putting all the information I need for my widget in to one module as I think this could make it very big and I could be repeating some of the data.




  2. Ivan Eftimov
    Ivan Eftimov avatar
    23 posts
    Registered:
    08 Feb 2017
    25 Apr 2012
    Link to this post
    Hello Owain,

    Yes, it is posible to merge multiple modules into one widget in the frontend.
    The first thing you need to do is to create a Custom Widget through Visual Studio, i.e. ASP.NET User Control (.ascx). Then you need to register your custom widget in Sitefinity:
        -    Administration -> Settings -> Advanced -> Toolboxes -> and then create new section and then create new tool (widget). Use the your User Control's Type or Virtual path to register it. Now your widget should be visible in the right panel, where other Sitefinity widgets are located.
    You can refer this article for more detials about creating custom controls/widgets.

    Next thing you do is integrate your Modules into the widget.
    Go to Administration -> Module Builder -> open the module you want to integrate and on the right you will see a link "Code Reference for [your module]". There you will find a link "Integration example for [your module]". This exmaple contains example markup and C# code behind for it, which you can paste in the custom control (widget) that you created before. It is not styled and formated but it will give you the basis, so you will be able to adjust it according to your needs.

    Here is a sample markup that your custom control (widget) should contain (.ascx)
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TwoModules.ascx.cs" Inherits="SitefinityWebApp.Widgets.TwoModules" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>  
    <!-- ScriptManager or RadScriptManager is required by RadGrid, but this tag probably already exists on the Master Template -->
    <!-- <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> -->
    <TELERIK:RADGRID id=Grid AutoGenerateColumns="False" runat="server">    
        <MASTERTABLEVIEW>        
            <COLUMNS>            
                <TELERIK:GRIDBOUNDCOLUMN HeaderText="Title" DataField="Title" />                         
            </COLUMNS>    
            <COLUMNS>
                <TELERIK:GRIDBOUNDCOLUMN HeaderText="Content" DataField="Content" />                  
            </COLUMNS>
            <COLUMNS>
                <TELERIK:GRIDBOUNDCOLUMN HeaderText="Abstract" DataField="Abstract" /> 
            </COLUMNS>
            <COLUMNS>
                <TELERIK:GRIDBOUNDCOLUMN HeaderText="Thumbnail" DataField="Thumbnail" />
            </COLUMNS>
     
        </MASTERTABLEVIEW>
    </TELERIK:RADGRID>
     
    <TELERIK:RADGRID id=Grid2 AutoGenerateColumns="False" runat="server">    
        <MASTERTABLEVIEW>        
            <COLUMNS>            
                <TELERIK:GRIDBOUNDCOLUMN HeaderText="Name" DataField="Name" />
            </COLUMNS>
            <COLUMNS>
                <TELERIK:GRIDBOUNDCOLUMN HeaderText="Comment" DataField="Comment" />                      
            </COLUMNS>    
        </MASTERTABLEVIEW>
    </TELERIK:RADGRID>

    and here is the correspondent C# code behind:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
     
    using Telerik.Sitefinity.Model;
    using Telerik.Sitefinity.DynamicModules;
    using Telerik.Sitefinity.Data.Linq.Dynamic;
    using Telerik.Sitefinity.DynamicModules.Model;
    using Telerik.Sitefinity.Utilities.TypeConverters;
    using Telerik.Sitefinity.GenericContent.Model;
      
     
     
    namespace SitefinityWebApp.Widgets
    {
        public partial class TwoModules : System.Web.UI.UserControl
        {                
                protected void Page_Load(object sender, EventArgs e)        
                {            
                    DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();           
                    Type articleType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Articles.Article");              
                    // Fetch a collection of "live" and "visible" Person items.            
                    var myCollection = dynamicModuleManager.GetDataItems(articleType).Where(i => i.Status == ContentLifecycleStatus.Live && i.Visible == true);              
                    // Binds the collection of Person items to the RadGrid            
                    Grid.DataSource = myCollection;            
                    Grid.DataBind();
     
                    Type commentType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Comments.Comment");
                    // Fetch a collection of "live" and "visible" Person items.            
                    myCollection = dynamicModuleManager.GetDataItems(commentType).Where(i => i.Status == ContentLifecycleStatus.Live && i.Visible == true);
                    // Binds the collection of Person items to the RadGrid            
                    Grid2.DataSource = myCollection;
                    Grid2.DataBind(); 
                }    
         }
    }

    I hope this long explanation will be helpful :). If you have any troubles do not hestitate to contact me.


    Best,
    Ivan
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Owain
    Owain avatar
    110 posts
    Registered:
    17 Jan 2012
    01 May 2012
    Link to this post
    Hi,
    thanks for the reply however what I am trying to do is, if I click on a map which has a location, which is stored in "location module", I would like to pull out the date from "information module" to match the location.
    Does that make sense?

    O.

  4. Ivan Eftimov
    Ivan Eftimov avatar
    23 posts
    Registered:
    08 Feb 2017
    07 May 2012
    Link to this post
    Hi,

    First, please accept my apologies for the delayed answer.
    The result you want to acheive, does make sense. If you succeed to display the two modules into one widget, I ithink that the rest is a mather of styling and filtering of the results.
    Anyway, I will still consider the posibility of using two separate widgets for the two modules.

    If you need more assistance, please do not hesitate to contact me again.

    Greetings,
    Ivan
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Owain
    Owain avatar
    110 posts
    Registered:
    17 Jan 2012
    08 May 2012
    Link to this post
    Ivan,
    Is there a way then, to import categories to modules?

    If I set a category or tag a module entry then I would be able to check to see if the two modules have a common tag/category set against them?


  6. Ivan Eftimov
    Ivan Eftimov avatar
    23 posts
    Registered:
    08 Feb 2017
    11 May 2012
    Link to this post
    Hello Owain,

    Hi Owain,
    You can assign a tag/category as a field (of type classification) on the custom module. To do that you go to Administration>Module Builder>select your module > [your module] item fields.
    So, you should create, let’s say, a Tags classification and add it as a field in your modules. Then assign the same tag names to the items you want to relate.
    Now, the coding part - you need to filter the items by their tag name. Following is a sample code:
    DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
    Type articleType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Articles.Article");
    Type commentType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Comments.Comment");
     
    var taxonomy = TaxonomyManager.GetManager().GetTaxonomies<FlatTaxonomy>().Where(
                                t => t.Name == "Tags").Single().Taxa.Where(t => t.Title == "first").SingleOrDefault();
     
    var myFilteredCollection = dynamicModuleManager.GetDataItems(articleType).Where(
                    x => x.GetValue<IList<Guid>>("Tags").Contains(taxonomy.Id) && x.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live);
                var myFilteredCollection2 = dynamicModuleManager.GetDataItems(commentType).Where(
                    x => x.GetValue<IList<Guid>>("Tags").Contains(taxonomy.Id) && x.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live);
     
                Grid3.DataSource = myFilteredCollection;
                Grid3.DataBind();
                Grid4.DataSource = myFilteredCollection2;
                Grid4.DataBind();

    the string "first" is the tag name used to relate the two items. As a modules i have used "Articles" and "Comments"; you should replace your modules' names in the code.

    Do not forget to use the following namespaces:
     using Telerik.Sitefinity.Taxonomies;
     using Telerik.Sitefinity.Taxonomies.Model;
     using Telerik.Sitefinity.Model; 

    For visual representation you can use the gids from before, and adjust their Visibility attribute in order to display or hide them depending on the situation. This is one way to do it.

    I hope this solution will help you solve your case. Do not hesitate to contact me for any further issues.

    Regards,
    Ivan
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
6 posts, 0 answered