Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get tag content in TagHelper

If I have a tag like:

<foo>Some content</foo>

How can I get the content in a TagHelper?

I can't see anything on TagHelper or TagHelperContext.

I'm trying to parse the content of a tag.

like image 955
BanksySan Avatar asked Oct 15 '25 18:10

BanksySan


1 Answers

The solution is a bit unintuitive, you get the content from the TagHelperOutput via the TagHelperOutput.GetChildContentAsync() method.

If we have a tag like so:

<my-tag>Some content</my-tag>

Then

public override void Process(TagHelperContext context, TagHelperOutput output)
{
    var childContext = output.GetChildContentAsync().Result;
    var content = childContext.GetContent();
    // content == "Some content"
}
like image 153
BanksySan Avatar answered Oct 18 '25 09:10

BanksySan