Skip to content

Commit

Permalink
Template functions: int - casting values to integers (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
Abbe98 authored Aug 17, 2023
1 parent db38f9c commit 5eaa6f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ The `uri` function takes a string and attempts to cast it to a URI, and produces
{{ uri "https://schema.org/Person" }}
```
##### Int
The `int` function takes a value and attempts to cast it to an integer, and produces an error upon failure.
```
{{ int "123" }}
```
##### Add
The `add` function sums integer values and takes at least two arguments.
Expand Down
3 changes: 3 additions & 0 deletions internal/template/function/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ var utilFuncs = map[string]interface{}{
"uri": func(value string) (rdf.IRI, error) {
return rdf.NewIRI(value)
},
"int": func(value interface{}) int {
return cast.ToInt(value)
},
"config": func() config.SiteConfig {
return config.CurrentSiteConfig
},
Expand Down

0 comments on commit 5eaa6f5

Please sign in to comment.