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.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
Foundations of Sitefinity ASP.NET Core Development
The free on-demand video course teaches developers how to use Sitefinity ASP.NET Core and take advantage of its decoupled architecture and modern development model.