Permalink
Browse files

Add Visibility Tag Helper

  • Loading branch information...
scottsauber committed Jan 4, 2017
1 parent 75c3f9f commit 8bd89a5c601adc80a361faf43d13179064b79230
@@ -0,0 +1,20 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace VisibilityTagHelperDemo.TagHelpers
{
[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;

public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
if (!IsVisible)
output.SuppressOutput();

return base.ProcessAsync(context, output);
}
}
}
@@ -2,6 +2,18 @@
ViewData["Title"] = "Home Page";
}

<div is-visible="true">
This should always be visible.
</div>

<div is-visible="false">
This should never be visible.
</div>

<div is-visible="User.Identity.IsAuthenticated">
This should only be visible if you're logged in.
</div>

<div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="6000">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
@@ -4,3 +4,4 @@
@using VisibilityTagHelperDemo.Models.ManageViewModels
@using Microsoft.AspNetCore.Identity
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, VisibilityTagHelperDemo

0 comments on commit 8bd89a5

Please sign in to comment.