Skip to content

Commit

Permalink
tpl: Add hasSuffix alias
Browse files Browse the repository at this point in the history
strings.HasPrefix already has an alias of hasPrefix
but strings.HasSuffix has no such alias.
This PR adds a hasSuffix alias to the tpl function with corresponding
function documentation.
It also adds a Minor update to the hasPrefix function documentation
re: keywords and relatedfuncs.

 Completes #10474
  • Loading branch information
jfish2 authored and bep committed Mar 8, 2023
1 parent 02ab77d commit d171d15
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/content/en/functions/hasPrefix.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ categories: [functions]
menu:
docs:
parent: "functions"
keywords: []
keywords: [strings]
signature: ["hasPrefix STRING PREFIX"]
workson: []
hugoversion:
relatedfuncs: []
relatedfuncs: [hasSuffix]
deprecated: false
aliases: []
---
Expand Down
21 changes: 21 additions & 0 deletions docs/content/en/functions/hasSuffix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: hassuffix
linktitle: hasSuffix
description: Tests whether a string ends with suffix.
date: 2023-03-01
publishdate: 2023-03-01
lastmod: 2023-03-01
categories: [functions]
menu:
docs:
parent: "functions"
keywords: [strings]
signature: ["hasSuffix STRING SUFFIX"]
workson: []
hugoversion:
relatedfuncs: [hasPrefix]
deprecated: false
aliases: []
---

* `{{ hasSuffix "Hugo" "go" }}` → true
8 changes: 8 additions & 0 deletions tpl/strings/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ func init() {
},
)

ns.AddMethodMapping(ctx.HasSuffix,
[]string{"hasSuffix"},
[][2]string{
{`{{ hasSuffix "Hugo" "go" }}`, `true`},
{`{{ hasSuffix "Hugo" "du" }}`, `false`},
},
)

ns.AddMethodMapping(ctx.ToLower,
[]string{"lower"},
[][2]string{
Expand Down

0 comments on commit d171d15

Please sign in to comment.