@@ -10,22 +10,42 @@ public class LinkTagHelper : TagHelper
10
10
[ HtmlAttributeName ( "Link" ) ]
11
11
public Link ? Link { get ; set ; }
12
12
13
+ /// <summary>
14
+ /// If the link should render child content even if there is no link
15
+ /// </summary>
16
+ [ HtmlAttributeName ( "Fallback" ) ]
17
+ public bool Fallback { get ; set ; }
18
+
19
+ /// <summary>
20
+ /// element to replace the anchor with when there is no link i.e div
21
+ /// </summary>
22
+ [ HtmlAttributeName ( "FallbackElement" ) ]
23
+ public string ? FallbackElement { get ; set ; }
24
+
13
25
public override async Task ProcessAsync ( TagHelperContext context , TagHelperOutput output )
14
26
{
15
- // Ensure we have a Url set on the LinkPicker property editor in Umbraco
16
- if ( string . IsNullOrWhiteSpace ( Link ? . Url ) )
17
- {
18
- output . SuppressOutput ( ) ;
19
- return ;
20
- }
21
-
22
27
// If the <our-link /> is self closing
23
28
// Ensure that our <a></a> always has a matching end tag
24
29
output . TagMode = TagMode . StartTagAndEndTag ;
25
-
26
30
output . TagName = "a" ;
31
+
27
32
var childContent = await output . GetChildContentAsync ( ) ;
28
33
34
+ // Ensure we have a Url set on the LinkPicker property editor in Umbraco
35
+ if ( string . IsNullOrWhiteSpace ( Link ? . Url ) )
36
+ {
37
+ if ( Fallback && ! childContent . IsEmptyOrWhiteSpace )
38
+ {
39
+ output . TagName = FallbackElement ;
40
+ }
41
+ else
42
+ {
43
+ output . SuppressOutput ( ) ;
44
+ }
45
+
46
+ return ;
47
+ }
48
+
29
49
// If we use the TagHelper <umb-link></umb-link>
30
50
// Without child DOM elements then it will use the Link Name property inside the <a> it generates
31
51
if ( childContent . IsEmptyOrWhiteSpace )
0 commit comments