internal static string Else(BlockHelperNode h, TemplateContext c) { if (!h.EvaluateExpression(c)) { return h.ResolveChildren(c); } else { return string.Empty; } }
public static string With(BlockHelperNode h, TemplateContext c) { // the "with" helper changes context to an item // referenced by the helper node expression var withContext = c.ResolveContext(h.Expression); if (withContext.HasData) { return h.ResolveChildren(withContext); } else { return string.Empty; } }
public static string Each(BlockHelperNode h, TemplateContext c) { // the "each" helper changes context to an enumerable item // referenced by the helper node expression var withContext = c.ResolveContext(h.Expression); var result = ""; if (withContext.IsEnumerable) { // each sub context is an item in the enumerable object // that was resolved in the parent context from the current node expression foreach (var subContext in withContext.AsEnumerable) { result += h.ResolveChildren(subContext); } return result; } else { return string.Empty; } }