You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On multi-site instances you might want to get all documents by type, within the site you are currently in. We ended up writing an extension method like this. Worth adding into the core code?
/// <summary>
/// Gets all documents of type T within the current internationalized site
/// </summary>
/// <param name="context">Umbraco context</param>
public static IEnumerable<T> GetByDocumentTypeWithinSite<T>(this IUmbracoContext context)
{
int rootNode = ResolveRootNodeId(context);
// Get all documents under the home node with the specified document type
// Document paths in the Umbraco cache are defined as "-1,<root node>,..."
var documents = Vault.Context.QueryRelative<T>(
XpathHelper.GetXpathForDocumentTypeUnderHomeNode(GetUmbracoEntityAliasFromType(typeof(T)), rootNode));
return documents;
}
/// <summary>
/// Gets the Xpath query for a document type underneith a home node id
/// </summary>
/// <param name="documentTypeId">The document type</param>
/// <param name="homeNodeId">The home node id</param>
public static string GetXpathForDocumentTypeUnderHomeNode(string documentTypeId, int homeNodeId)
{
return string.Format("//{0}[starts-with(@path, '-1,{1},')]", documentTypeId, homeNodeId);
}
The text was updated successfully, but these errors were encountered:
On multi-site instances you might want to get all documents by type, within the site you are currently in. We ended up writing an extension method like this. Worth adding into the core code?
The text was updated successfully, but these errors were encountered: