Skip to content

Instantly share code, notes, and snippets.

@skttl
Created September 24, 2018 09:05
Show Gist options
  • Save skttl/7dbfebd2826a78cc2b90d9e2d58fd402 to your computer and use it in GitHub Desktop.
Save skttl/7dbfebd2826a78cc2b90d9e2d58fd402 to your computer and use it in GitHub Desktop.
@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