Hiding Custom Field Sections for Different Providers with Sitefinity Multisite Management

Hiding Custom Field Sections for Different Providers with Sitefinity Multisite Management

Posted on December 20, 2013 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.

In a multisite management scenario all Sitefinity modules have the same custom and built-in fields for all sites because custom fields are added to a whole type (NewsItem, BlogPost, etc.) and are not unique per site.

A customization can be added to make certain fields hidden in some sites to achieve different custom and built-in fields population. In this blog post I will present a solution to this.

Here is a video which demonstrates the results of the below steps to hide custom fields for different sites.

1. Create javascipt file in your project and place the below javascript in it.

ActionStart = function () // Sitefinity LoadMethodName
{
    var urlParams = {};
    (function () {
        var match,
        pl = /\+/g,  // Regex for replacing addition symbol with a space
        search = /([^&=]+)=?([^&]*)/g,
        decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
        query = window.location.search.substring(1);
  
        while (match = search.exec(query))
            urlParams[decode(match[1])] = decode(match[2]);
    })();
  
    if (urlParams["provider"]) {
        if (urlParams["provider"] == 'newsProvider2') {
            $('.sfFormIn').each(function () {
                //debugger;
                if (($.trim($(this).find('h2 a').text()) == 'CustomFieldsSection') || ($.trim($(this).find('h2 a').text()) == 'More options (URL, Comments)')) {
                    // debugger;
                    $(this).parent().hide();
                }
            })
        }
    }
};

 2. Register this script to be executed when News items are edited:

Go to Administration->Settings->Advanced->ContentView->Controls->NewsBackend->NewsBackendEdit->Scripts and create new script. Fill in the textboxes with a relative path to the javascript file from step 1 and for Action method fill in ActionStart (it is also contained in the javascript file).

3. All custom fields are added to the CustomFieldsSection by default and to easily hide whole sections of custom fields trough the above script, make the default custom fields section collapse. Here is a screenshot on what properties to add to the existing custom fields section to make it collapse. Go to Administration->Settings->Advanced->ContentView->Controls->NewsBackend->NewsBackendEdit->Sections->CustomFieldSection.

Additional sections for hosting custom fields can be added and to move custom fields into new sections go to App_Data/Sitefinity/Configuration/NewsConfig.contentViewControls.NewsBackend.views.NewsBackendEdit.config and move different custom fields into the newly created sections.

This will make the custom fields section hidden when the provider for news used is named newsProvider2.

if (urlParams["provider"]) {
        if (urlParams["provider"] == 'newsProvider2') {
            $('.sfFormIn').each(function () {

In the multisite scenario for each site the news module gets added to a different provider. To check the provider name as shown in the video above, the provider name can be retrieved from the query string when this provider is requested.

To check the provider name I have added a provider from another site (here is a screenshot) so I can have two providers. The second provider can be removed if not needed after tests have completed for news module custom fields for this site.
The script removes a whole section named CustomFieldsSection. Use this approach to separate different fields in news module into sections and hide those fields in different providers/sites.

if (($.trim($(this).find('h2 a').text()) == 'CustomFieldsSection') || ($.trim($(this).find('h2 a').text()) == 'More options (URL, Comments)')) {
                    // debugger;
                    $(this).parent().hide();
                }

Stanislav Velikov

Stanislav Velikov is a Tech Support Engineer at Telerik. He joined the Sitefinity Support team in April 2011.

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