Skip to content

Instantly share code, notes, and snippets.

@josephwoodward
Last active July 14, 2017 10:09
Show Gist options
  • Save josephwoodward/7bc9f76c471078efda93b16f63ae4a23 to your computer and use it in GitHub Desktop.
Save josephwoodward/7bc9f76c471078efda93b16f63ae4a23 to your computer and use it in GitHub Desktop.
[HtmlTargetElement("div")]
public class VisibilityTagHelper : TagHelper
{
public bool IsVisible { get; set; } = true;
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);
}
}
@josephwoodward
Copy link
Author

Allows you to use:

<div is-visible="@Model.LoggedIn">
<p>For logged in eyes only</p>
</div>

instead of

@if (Model.LoggedIn)
{
<p>For logged in eyes only</p>
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment