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 will describe how to create a layout widget that hides its content from the search engine in Sitefinity. This type of layout widget is useful if you want to hide a content block from the indexing or you don't want to write the same control logic for every widget you develop. Writing this layout widget is pretty simple. All that has to be done is to extend the built-in control LayoutControl and reuse the layout templates.
So let's start by adding a new class to your SitefinityWebApp project. Give it a proper name (in this sample it is called NonSearchableLayout) and make it to extend the LayoutControl.
Next we'll override two of the methods of System.Web.UI.Control class:
The GetIndexRenderMode() method is an extension method. It says whether the page is rendered by the search engine or it is rendered normally. Setting the Visible property of the control to False makes the control to skip the work it usually does when it is visible. It even skips calling the Render method but for any case we'll override the Render method too.
And here is a complete listing of the code (I put it for the sake of completeness):
So this is it. Build the SitefinityWebApp project and the layout widget is ready to be registered in Sitefinity. The documentation page for registering custom layout widgets is here, but here is what to be done:
Now you can edit one of your pages and give a try to the new layout widget.
I want to add a note about the usage of this layout. You may ask do you need such layout widget for the other template types ("Two columns with 50% width each.", etc.) The good thing is that you can use the other layouts with this new one in various combinations. For example you don't want the content inside one of your layouts to be indexed. Simply drop a non searchable layout and move the other layout inside. Or you may want the content inside the left part of one of your layouts not to be indexed. In this case drop the new layout in the left part of the existing layout and move its content to the new layout. You can even position a layout widget among other widgets (Content Blocks, News Widget, etc) so you can exclude a certain widget from the search and not exclude its neighbor widgets.
The layout widgets of Sitefinity are a really powerful instrument that can be used for purposes not only related to styling. In this case we used them to change the behavior of other widgets in different scenarios.
If you have a question or want to make a suggestion please leave a comment.
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.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.Learn More
Subscribe to get all the news, info and tutorials you need to build better business apps and sites
You have the right to request deletion of your Personal Information at any time.
You can also ask us not to pass your Personal Information to third parties here: Do Not Sell My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.