Skip to content

Instantly share code, notes, and snippets.

@enkelmedia
Created December 18, 2018 09:42
Show Gist options
  • Save enkelmedia/0d25da7405415b5a7f5c0a166b44f9b2 to your computer and use it in GitHub Desktop.
Save enkelmedia/0d25da7405415b5a7f5c0a166b44f9b2 to your computer and use it in GitHub Desktop.
Umbraco Helper Extentions for getting nodes by property value, attribute value and by document type alias
public static class UmbracoHelperExtensions
{
public static IEnumerable<IPublishedContent> TypedContentByPropertyValue(this UmbracoHelper helper, string propertyName, string value, string documentTypeAlias = "")
{
if (string.IsNullOrEmpty(documentTypeAlias))
documentTypeAlias = "*";
// format: var all = Umbraco.TypedContentAtXPath("//jobListing[englishUrlName = 'test']");
return helper.TypedContentAtXPath($"//{documentTypeAlias}[{propertyName} = '{value}']");
}
public static IEnumerable<IPublishedContent> TypedContentByAttributeValue(this UmbracoHelper helper, string attributeName, string value, string documentTypeAlias = "")
{
if (string.IsNullOrEmpty(documentTypeAlias))
documentTypeAlias = "*";
// format: var all = Umbraco.TypedContentAtXPath("//jobListing[@urlName = 'online-support']");
return helper.TypedContentAtXPath($"//{documentTypeAlias}[@{attributeName} = '{value}']");
}
public static IEnumerable<IPublishedContent> TypedContentByContentType(this UmbracoHelper helper, string contentTypeAlias)
{
// format: var all = Umbraco.TypedContentAtXPath("//jobListing"); where "jobListing" is the document/content type alias
return helper.TypedContentAtXPath($"//{contentTypeAlias}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment