More in this section
Categories
Bloggers
Blogs RSS feed

Hiding Custom Field Sections for Different Providers with Sitefinity Multisite Management

by Stanislav Velikov
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();
                }

17 comments

Leave a comment
  1. Saad Khan Sep 23, 2015

    How can I change provider of Related Data Field on the fly? Can I add this kind of js to change Related Data Field provider so that it shows me current provider items only. Right now its only showing me OpenAccessProvider items.

  2. robert May 17, 2018
    This article was written by a real thinking writer.  I agree many of the with the solid points made by the writer.  I’ll be back.corporate film
  3. robert May 17, 2018
    You have done a great job on this article.  It’s very readable and highly intelligent.  You have even managed to make it understandable and easy to read.  You have some real writing talent. Thank you.franklin sellers agent
  4. robert May 17, 2018
    nice post, keep up with this interesting work. It really is good to know that this topic is being covered also on this web site so cheers for taking time to discuss this!surfcamp adolescentes verano
  5. robert May 17, 2018
    Nice to be visiting your blog once more, it has been months for me. Well this article that ive been waited for therefore long. i want this article to finish my assignment within the faculty, and it has same topic together with your article. Thanks, nice share.advanced printing nyc
  6. robert May 17, 2018
    An fascinating discussion is value comment. I think that it is best to write extra on this matter, it won’t be a taboo topic however generally people are not enough to talk on such topics. To the next. Cheersfranklin sellers agent
  7. robert May 17, 2018
    Best work you have done, this online website is really cool with great facts.Breast Revision
  8. robert May 17, 2018
    Nice post. I was checking constantly this blog and I am impressed! Extremely helpful information specially the last part   I care for such info a lot. I was seeking this particular information for a very long time. Thank you and good luck.best fertility doctor in hyderabad
  9. robo Jun 07, 2018
    Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking.Detective en Madrid
  10. sami Jun 23, 2018
    Hi there! Nice post! Please tell us when I will see a follow up!Detective en Madrid
  11. jone Jun 26, 2018
    Thank you a bunch for sharing this with all of us you actually realize what you are talking about! Bookmarked. Please also seek advice from my site =). We could have a hyperlink change contract between us!flowers Scottsdale
  12. robert Jun 30, 2018
    I am very enjoyed for this blog. Its an informative topic. It help me very much to solve some problems. Its opportunity are so fantastic and working style so speedy.ccna weekend courses london
  13. robert Jun 30, 2018
    Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts.mcsa training
  14. robert Jun 30, 2018
    You’ve got some interesting points in this article. I would have never considered any of these if I didn’t come across this. Thanks!.3D brows
  15. jone Jul 04, 2018
    There is so much in this article that I would never have thought of on my own. Your content gives readers things to think about in an interesting way. Thank you for your clear information.DETECTIVES MADRID
  16. detective Jul 17, 2018
    I admire what you have done here. I like the part where you say you are doing this to give back but I would assume by all the comments that this is working for you as well.detective Madrid
  17. Hong Leong Holdings Orchard Condo Jul 17, 2018
    Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!Hong Leong Holdings Orchard Condo

    Leave a comment