Skip to content

Commit

Permalink
Add Visibility Tag Helper
Browse files Browse the repository at this point in the history
  • Loading branch information
scottsauber committed Jan 4, 2017
1 parent 75c3f9f commit 8bd89a5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
@@ -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);
}
}
}
Expand Up @@ -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>
Expand Down
Expand Up @@ -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.