Created
December 18, 2018 09:42
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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