Using ASP.Net Core's Tag Helpers, is there any way to convert 1 tag into 2 tags at the root level? I know you can remove a tag completely using TagHelperOutput.TagName == null
, but I'm wondering how I can do the opposite to output more than one tag.
For example, go from:
<canonical href="/testing" />
to:
<link rel="canonical" href="http://www.examples.com/widgets" />
<link rel="next" href="http://www.examples.com/widgets?page=2" />
Here is an example tag helper that outputs one of the tags, but not both:
[HtmlTargetElement("canonical")]
public class CanonicalLinkTagHelper : TagHelper
{
public string Href { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "link";
output.Attributes.SetAttribute("rel", "canonical");
output.Attributes.SetAttribute(new TagHelperAttribute("href", new HtmlString(Href)));
}
}
output.PostContent.AppendHtml
? – Contaminate