Skip to content

Commit 2a51693

Browse files
author
Warren Buckley
committed
Fix up the suggestons to get it to build again
1 parent ccb947b commit 2a51693

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Our.Umbraco.TagHelpers/IsActivePageTagHelper.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Microsoft.AspNetCore.Razor.TagHelpers;
2+
using System.Text.Encodings.Web;
23
using Umbraco.Cms.Core.Web;
34
using Umbraco.Extensions;
5+
using Microsoft.AspNetCore.Mvc.TagHelpers;
46

57
namespace Our.Umbraco.TagHelpers
68
{
@@ -12,9 +14,10 @@ namespace Our.Umbraco.TagHelpers
1214
/// if the value in the href of the <a> compared to the page being rendered
1315
/// is the current page or part of an ancestor
1416
/// </summary>
15-
[HtmlTargetElement("a", Attributes = "our-is-active-page")]
17+
[HtmlTargetElement("a", Attributes = tagHelperAttributeName)]
1618
public class IsActivePageTagHelper : TagHelper
1719
{
20+
private const string tagHelperAttributeName = "our-active-class";
1821
private IUmbracoContextAccessor _umbracoContextAccessor;
1922

2023
public IsActivePageTagHelper(IUmbracoContextAccessor umbracoContextAccessor)
@@ -26,7 +29,7 @@ public IsActivePageTagHelper(IUmbracoContextAccessor umbracoContextAccessor)
2629
/// The CSS class name you wish to append to the class attribute
2730
/// on an <a> tag when the page is active/selected
2831
/// </summary>
29-
[HtmlAttributeName("our-is-active-page")]
32+
[HtmlAttributeName(tagHelperAttributeName)]
3033
public string ActiveClassName { get; set; }
3134

3235
public override void Process(TagHelperContext context, TagHelperOutput output)
@@ -62,7 +65,7 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
6265
if(nodeOfLink.IsAncestorOrSelf(currentPageRendering))
6366
{
6467
// Is active page
65-
output.Attributes.AddClass(ActiveClassName, HtmlEncoder.Default);
68+
output.AddClass(ActiveClassName, HtmlEncoder.Default);
6669
}
6770
}
6871
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ If you want the edit link to open in a new tab, just add the `target="_blank"` a
292292
<our-edit-link target="_blank">Edit</our-edit-link>
293293
```
294294

295-
## `our-is-active-page`
295+
## `our-active-class`
296296
This is a tag helper attribute that can be applied to `<a>` element in the razor template or partial. It will use the value inside the attribute and append it to the class attribute of the `<a>`.
297297
If the link inside the href attribute can be found by its route as a content node, if so then it will check with the current page being rendered if its the same node or an ancestor.
298298

@@ -302,7 +302,7 @@ This allows for the navigation item to still have the class added to it when a c
302302
```cshtml
303303
@foreach (var item in Model.Root().Children)
304304
{
305-
<a href="@item.Url()" class="nav-link" our-is-active-page="nav-link--active">@item.Name</a>
305+
<a href="@item.Url()" class="nav-link" our-active-class="nav-link--active">@item.Name</a>
306306
}
307307
```
308308

0 commit comments

Comments
 (0)