Products module: Removing unneeded Generic Content features

Products module: Removing unneeded Generic Content features

Posted on March 23, 2009 0 Comments

The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

[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.
progress-logo

The Progress Team

View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.

Comments

Comments are disabled in preview mode.
Topics

Sitefinity Training and Certification Now Available.

Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.

Learn More
Latest Stories
in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation