hugo/content/en/functions/trim.md
Bjørn Erik Pedersen b9bd35d72e Squashed 'docs/' content from commit fdea5430f
git-subtree-dir: docs
git-subtree-split: fdea5430f89dfd849d39212abdf5ace0a4763e5a
2019-10-21 10:22:28 +02:00

1.1 KiB

title description godocref date publishdate lastmod categories menu keywords signature workson hugoversion relatedfuncs deprecated
trim Returns a slice of a passed string with all leading and trailing characters from cutset removed. 2017-02-01 2017-02-01 2017-02-01
functions
docs
parent
functions
strings
trim INPUT CUTSET
false
{{ trim "++Batman--" "+-" }} → "Batman"

trim requires the second argument, which tells the function specifically what to remove from the first argument. There is no default value for the second argument, so the following usage will not work:

{{ trim .Inner}}

Instead, the following example tells trim to remove extra new lines from the content contained in the shortcode .Inner variable:

{{ trim .Inner "\n" }}

{{% note %}} Go templates also provide a simple method for trimming whitespace from either side of a Go tag by including a hyphen (-). {{% /note %}}