How about creating a @helper method, which can be put in App_code folder and be used on any of your Razor files? Or an extension method on the Model that returns a DynamicNodeList, probably taking your propery alias as additional parameter?
BTW: related pages is uComponents MNTP saving in XML format.
@Dirk unfortunately you can't have extension methods on dynamic objects, I tried that.
However I just tried the obvious solution again and this time it works, I don't know If I failed last time or because we updated to latest macroEngine, but here it is, moving it into a static helper class:
using System.Collections.Generic;
using System.Web;
using umbraco.MacroEngines.Library;
namespace Terabyte.Umbraco.Extensions
{
public static class DynamicNodeExtensions
{
public static IEnumerable<dynamic> GetPublishedNodes(dynamic property)
{
foreach (var nodeId in property)
{
var page = (new RazorLibraryCore(null)).NodeById(nodeId.InnerText);
if (page.Id != 0)
{
yield return page;
}
}
}
}
}
In need of Razor syntactic sugar to help with 'is published' checking.
Hi all
Here's a pretty common scenario we face, and I'm wanting a way to make this DRYer.
How can I separate out all the logic above the 'HTML HERE' line into something re-usable?
Hi Murray,
How about creating a @helper method, which can be put in App_code folder and be used on any of your Razor files? Or an extension method on the Model that returns a DynamicNodeList, probably taking your propery alias as additional parameter?
Hope this helps.
Regards,
/Dirk
BTW: related pages is uComponents MNTP saving in XML format.
@Dirk unfortunately you can't have extension methods on dynamic objects, I tried that.
However I just tried the obvious solution again and this time it works, I don't know If I failed last time or because we updated to latest macroEngine, but here it is, moving it into a static helper class:
and the razor:
Improvements welcome
is working on a reply...