+1-888-365-2779
Try Now
More in this section
Categories
Bloggers
Blogs RSS feed

Products module: Removing unneeded Generic Content features

by Ivan Osmak
[This post is part of the developer's manual preview published on this blog. You can find temporary TOC here.]

 

Ability to reuse already developed functionality is one of the most convincing reasons to base your module on Generic Content module and not build a module from scratch. However, the module that is being built will necessary be different than the one we are basing it on - otherwise it would make no sense to build a new module - we could just use the existing one.

 

So far we have seen and learned how to reuse functionality - in this article we are going to examine different approaches for removing or abandoning functionality implemented on Generic Content module.

 

There are two basic ways to remove functionality:
  • Remove or don’t add a View which is responsible for a given functionality
  • Modify the View to restrict its abilities

Omitting Views


The simplest way to remove a functionality implemented on the base module is simply to omit the View for it. This can be done either through ControlsConfig file as explained here or in the overridden CreateViews method of the host View.

 

Let us suppose we are to remove comments functionality from our Products module. Since we have added ProductsCommentsView in the ProductsControlPanel View, we can simply comment that line out, like follows:
/// <summary> 
/// Loads configured views. 
/// </summary> 
protected override void CreateViews() 
AddView<ProductsView>("ProductsView""ProductsView_Title""ProductsView_Description""all", Messages.ResourceManager); 
AddView<ProductsCategoriesView>("ProductsCategoriesView""CategoriesView_Title""CategoriesView_Description""all", Messages.ResourceManager); 
AddView<ProductsTagsView>("ProductsTagsView""TagsView_Title""TagsView_Description""all", Messages.ResourceManager); 
//AddView<ProductsCommentsView>("ProductsCommentsView", "CommentsView_Title",     
// "CommentsView_Description", "all", Messages.ResourceManager); 
AddView<ProductsPermissionsView>("ProductsPermissionsView""PermissionsView_Title""PermissionsView_Description""globalPerm", Messages.ResourceManager); 

 

Modify the View to restrict its abilities


Sometimes, we may have the need to remove certain functionality of the base Generic Content module, because it does not fit well into our requirements. Let us suppose that we wish to remove the listing of all meta field values from the ProductPreviewView as demonstrated on the below screenshot:

To achieve this, all we need to do is following:

 

Wrap the details panel into a server control. We’ll do this by editing the embedded for the ProductsPreviewView template located in Telerik.Samples.Products.Resources.ControlTemplates.Backend.ProductsPreviewView.ascx in following manner:

<div id="detailsPanel" runat="server" class="details"
                    <h3> 
                        <asp:Literal Text="<%$Resources:Details %>" runat="server" /> 
                    </h3> 
                    <dl> 
                        <asp:Repeater ID="repeaterItemMetaData" runat="server"
                        <ItemTemplate> 
                                <dt> 
                                    <asp:Literal ID="lblKey" runat="server" /> 
                                </dt> 
                                <dd> 
                                    <asp:Literal ID="lblValue" runat="server" /> 
                                </dd> 
                        </ItemTemplate> 
                        </asp:Repeater> 
                    </dl> 
    </div> 
 
Notice that we have simply added the id and runat attribute to the wrapping div element.

 

Next, in the ProductsPreviewView class, we’ll add a reference to the detailsPanel control.

protected Control DetailsPanel 
            get 
            { 
                return base.Container.GetControl<Control>("detailsPanel"false); 
            } 
 
And finally, in ProductsPreviewView we will also override the InitializeControls method. We will call the base implementation first and let is set up the View as always, but then after that, we will hide the DetailsPanel. The code for this method will look like following:

protected override void InitializeControls(System.Web.UI.Control viewContainer) 
            base.InitializeControls(viewContainer); 
             
            if(this.DetailsPanel != null
                this.DetailsPanel.Visible = false
 

Conclusion


Hardly anything revolutionary has been explained in this article. The important thing to take from this article is the notion of highly decoupled architecture that the new backend in Sitefinity 3.6 has brought us. As it was demonstrated we are able to pick highly isolated functionality (Views) of the base module and remove them from our implementation, just as we are able to go even further down and remove only parts of these Views - like in the second sample with the DetailsPanel.

Leave a comment