Merge pull request #1897 from dapr/aacrawfi/button-fix

Update button shortcode so links open in new tab
This commit is contained in:
greenie-msft 2021-11-03 10:02:47 -07:00 committed by GitHub
commit efeb4cb0e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -334,6 +334,8 @@ The shortcode would be:
To create a button in a webpage, use the `button` shortcode. To create a button in a webpage, use the `button` shortcode.
An optional "newtab" parameter will indicate if the page should open in a new tab. Options are "true" or "false". Default is "false", where the page will open in the same tab.
#### Link to an external page #### Link to an external page
``` ```
@ -346,10 +348,10 @@ To create a button in a webpage, use the `button` shortcode.
You can also reference pages in your button as well: You can also reference pages in your button as well:
``` ```
{{</* button text="My Button" page="contributing" */>}} {{</* button text="My Button" page="contributing" newtab="true" */>}}
``` ```
{{< button text="My Button" page="contributing" >}} {{< button text="My Button" page="contributing" newtab="true" >}}
#### Button colors #### Button colors

View File

@ -2,7 +2,8 @@
{{ $page := .Get "page" }} {{ $page := .Get "page" }}
{{ $link := .Get "link" | default "#" }} {{ $link := .Get "link" | default "#" }}
{{ $text := .Get "text" }} {{ $text := .Get "text" }}
{{ $newtab := .Get "newtab" | default "false" }}
{{- if $page -}}{{- $link = ref . $page -}}{{- end -}} {{- if $page -}}{{- $link = ref . $page -}}{{- end -}}
<a class="btn btn-{{ $color }}" href="{{ $link }}" role="button">{{ $text }}</a> <a class="btn btn-{{ $color }}" href="{{ $link }}" role="button" {{- if eq $newtab "true" -}}target="_blank"{{- end -}}>{{ $text }}</a>