/// <summary> /// Executes this tag. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> protected override void DoExecute(IMansionContext context) { // get arguments var targetDataspace = GetRequiredAttribute<string>(context, "target"); var global = GetAttribute(context, "global", false); // create the loop var start = GetAttribute(context, "start", 0); var end = Math.Max(start, GetAttribute(context, "end", int.MaxValue)); var loop = new Loop(context.Reader, start, end); // push the loop to the stack using (context.Stack.Push("Loop", loop)) { // loop through all the rows foreach (var row in loop.Rows) { // push the row to the stack using (context.Stack.Push(targetDataspace, row, global)) ExecuteChildTags(context); } } }
/// <summary> /// Renders the crumb trail. /// </summary> /// <param name="context"></param> /// <param name="trail"></param> /// <returns></returns> private string RenderTrail(IMansionContext context, IEnumerable<Crumb> trail) { // validate arguments if (context == null) throw new ArgumentNullException("context"); if (trail == null) throw new ArgumentNullException("trail"); // create a dataset from the trail var dataset = new Dataset(); foreach (var crumb in trail) dataset.AddRow(PropertyBagAdapterFactory.Adapt(context, crumb)); // create a buffer in which to store the output var templateBuffer = new StringBuilder(); using (var templateBufferPipe = new StringOutputPipe(templateBuffer)) using (context.OutputPipeStack.Push(templateBufferPipe)) using (templateService.Render(context, "CrumbTrail", TemplateServiceConstants.OutputTargetField)) { // create the loop var loop = new Loop(dataset); using (context.Stack.Push("Loop", loop)) { // render the leafs recursively foreach (var crumb in loop.Rows) { using (context.Stack.Push("CrumbProperties", crumb)) templateService.Render(context, "CrumbTrailItem").Dispose(); } } } // return the contents of the buffer return templateBuffer.ToString(); }