You can query a content block by its ID. To search for a content blocks based on other property or criteria, see For developers: Find content blocks.
NOTE: The code examples below work with the ID of the master version of the content block. The examples return the master version. For more information about querying by the ID of the live version and returning the live version, see For developers: Query master and live versions.
To query a content block you can use the Native API or the Fluent API:
To query a specific content block using the Native API, you use the ContentManager class.
The following code queries the content block by its ID:
You use the GetContent method and filter based on the Id property. If the content block does not exist, the method returns null.
To find the content block, you can also use the GetContent method passing contentItemId, in the following way:
ContentItem contentItem = manager.GetContent(contentItemId);
To query a content block using the Fluent API, you use the content block facade. The following code queries the content block by its ID:
You first initialize the plural content block facade using App.WorkWith().ContentItems(). Then, you filter the content blocks based on the Id property. Finally, you use the Get method to get the content block. If the content block does not exist, the method returns null.
To find the content block, you can also use the singular content block facade, in the following way:
ContentItem contentItem = App.WorkWith().ContentItem(contentItemId).Get();
If there is no content block with the specified Id, the call to ContentItem(contentItemId) throws an exception of type ItemNotFoundException.
Back To Top
Copyright © 2018 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.