示例#1
0
        protected override async Task ProcessCoreAsync(TagHelperContext context, TagHelperOutput output)
        {
            var isHtmlTag = output.TagName != "zone";

            var widgets = await _widgetSelector.GetWidgetsAsync(ZoneName, ViewContext.ViewData.Model);

            if (!isHtmlTag)
            {
                // Never render <zone> tag
                output.TagName = null;
            }

            if (widgets.Any())
            {
                if (ReplaceContent)
                {
                    output.Content.SetContent(string.Empty);
                }

                foreach (var widget in widgets)
                {
                    var target      = widget.Prepend ? output.PreContent : output.PostContent;
                    var viewContext = Model == null ? ViewContext : ViewContext.Clone(Model);

                    target.AppendHtml(await widget.InvokeAsync(viewContext));
                }
            }
            else
            {
                // No widgets
                if (RemoveIfEmpty && output.TagName.HasValue())
                {
                    var childContent = await output.GetChildContentAsync();

                    if (childContent.IsEmptyOrWhiteSpace)
                    {
                        output.TagName = null;
                    }
                }
            }
        }