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
// Add more target elements here on a new line if you want to target more than just div. Example: [HtmlTargetElement("a")] to hide/show links | |
[HtmlTargetElement("div")] | |
public class VisibilityTagHelper : TagHelper | |
{ | |
// default to true otherwise all existing target elements will not be shown, because bool's default to false | |
public bool IsVisible { get; set; } = true; | |
// You only need one of these Process methods, but just showing the sync and async versions | |
public override void Process(TagHelperContext context, TagHelperOutput output) | |
{ | |
if (!IsVisible) | |
output.SuppressOutput(); | |
base.Process(context, output); | |
} | |
public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output) | |
{ | |
if (!IsVisible) | |
output.SuppressOutput(); | |
return base.ProcessAsync(context, output); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment