public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { await base.ProcessAsync(context, output); output.Attributes.RemoveAll("condition"); if (context.TagName.Equals("if", StringComparison.OrdinalIgnoreCase)) { output.TagName = null; } var ctx = ConditionalContext.GetFromContext(context); var innerContent = await output.GetChildContentAsync(); if (ctx.NeedsElseContent) { if (ctx.ElseContent == null) { output.SuppressOutput(); } else { output.Content.SetHtmlContent(ctx.ElseContent); } } }
public override void Init(TagHelperContext context) { base.Init(context); var ctx = ConditionalContext.GetFromContext(context); ctx.NeedsElseContent = ShouldSuppress(); }
public static ConditionalContext GetFromContext(TagHelperContext context) { if (!context.Items.TryGetValue(nameof(ConditionalContext), out var ctx)) { ctx = new ConditionalContext(); context.Items.Add(nameof(ConditionalContext), ctx); } return((ConditionalContext)ctx); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var ctx = ConditionalContext.GetFromContext(context); if (ctx.NeedsElseContent) { ctx.ElseContent = await output.GetChildContentAsync(); } output.SuppressOutput(); }