Skip to content

Commit 5eaa6f5

Browse files
authored
Template functions: int - casting values to integers (#76)
1 parent db38f9c commit 5eaa6f5

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ The `uri` function takes a string and attempts to cast it to a URI, and produces
246246
{{ uri "https://schema.org/Person" }}
247247
```
248248
249+
##### Int
250+
251+
The `int` function takes a value and attempts to cast it to an integer, and produces an error upon failure.
252+
253+
```
254+
{{ int "123" }}
255+
```
256+
249257
##### Add
250258
251259
The `add` function sums integer values and takes at least two arguments.

internal/template/function/utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ var utilFuncs = map[string]interface{}{
2121
"uri": func(value string) (rdf.IRI, error) {
2222
return rdf.NewIRI(value)
2323
},
24+
"int": func(value interface{}) int {
25+
return cast.ToInt(value)
26+
},
2427
"config": func() config.SiteConfig {
2528
return config.CurrentSiteConfig
2629
},

0 commit comments

Comments
 (0)