This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WrapperTagHelper : TagHelper | |
{ | |
public override void Process(TagHelperContext context, TagHelperOutput output) | |
{ | |
output.TagName = "div"; | |
output.Attributes.SetAttribute(new TagHelperAttribute("class", "wrapper-tag-helper")); | |
string innerContent = renderInnerTagHelper(context); | |
string finalContent = $@"<p>Wrapper</p> | |
{innerContent}"; | |
output.Content.SetHtmlContent(finalContent); | |
} | |
/* | |
* This methods creates, processes and renders the InnerTagHelper | |
*/ | |
private string renderInnerTagHelper(TagHelperContext context) | |
{ | |
InnerTagHelper innerTagHelper = new InnerTagHelper(); | |
// Create a TagHelperOutput instance | |
TagHelperOutput innerOutput = new TagHelperOutput( | |
tagName: "", | |
attributes: new TagHelperAttributeList(), | |
getChildContentAsync: (useCachedResult, encoder) => | |
Task.Factory.StartNew<TagHelperContent>( | |
() => new DefaultTagHelperContent() | |
) | |
); | |
// Process the InnerTagHelper instance | |
innerTagHelper.Process(context, innerOutput); | |
// Render and return the tag helper attributes and content | |
return $"<{innerOutput.TagName} {renderHtmlAttributes(innerOutput)}>{innerOutput.Content.GetContent()}</{innerOutput.TagName}>"; | |
} | |
. | |
. | |
<code omitted here> | |
. | |
. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment