Search for a content block by title

You can search for a content block with the Native API or with the Fluent API.

Search with the Native API

To search for a content block by its Titleusing Native API, you use the ContentManager class.

You first initialize ContentManager. Then, you get all content blocks using GetContent() and filter based on the Titleand Statusproperties:

C#
using System.Linq;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Modules.GenericContent;

namespace SitefinityWebApp
{
   public class QueryContentBlockByTitle
   {
       public ContentItem GetContentItemByTitleNative(string title)
       {
           ContentManager manager = ContentManager.GetManager();
           var contentItem = manager.GetContent().Where(cI => (cI.Title == title && cI.Status == ContentLifecycleStatus.Live)).FirstOrDefault();
           return contentItem;
       }
   }
}

Search with the Fluent API

To search for a content block by its Titleusing Fluent API, you use the plural content block facade.

You first initialize the plural content block facade using App.WorkWith().ContentItems(). Then, you filter based on the Titleand Status properties. Finally, to get the content block, you use the Get method:

C#
using System.Linq;
using Telerik.Sitefinity;
using Telerik.Sitefinity.GenericContent.Model;

namespace SitefinityWebApp
{
   public class QueryContentBlockByTitleFluentAPI
   {
       public ContentItem GetContentItemByTitleFluent(string title)
       {
           ContentItem contentItem = App.WorkWith().ContentItems().Where(cI => (cI.Title == title && cI.Status == ContentLifecycleStatus.Live)).Get().FirstOrDefault();
           return contentItem;
       }
   }
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.