Created
September 24, 2018 09:05
-
-
Save skttl/7dbfebd2826a78cc2b90d9e2d58fd402 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@using Umbraco.Core.Models; | |
@using Umbraco.Web; | |
@using System.Collections.Generic; | |
namespace skttl.UmbracoExtensions | |
{ | |
public static class UmbracoHelperExtensions | |
{ | |
public static IEnumerable<IPublishedContent> TypedContentAtRelativeXPath(this UmbracoHelper helper, IPublishedContent current, string xpath) | |
{ | |
return helper.TypedContentAtXPath(PathToXPath(current.Path) + xpath); | |
} | |
public static IPublishedContent TypedContentSingleAtRelativeXPath(this UmbracoHelper helper, IPublishedContent current, string xpath) | |
{ | |
return helper.TypedContentSingleAtXPath(PathToXPath(current.Path) + xpath); | |
} | |
private static string PathToXPath(string input) | |
{ | |
return string.Join("", input.Split(',').Select(x => "/[@id='" + x + "']")) + "/"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment