How to get the total value from the specific params. Let say I have a param called fund in my project section/content,
---
fund: 7000 #value that i need to calculate
---
what I need is to sum/calculate that from every project I made in my home page for example <span>total fund<span>....
with my limitation I try to use len and add
{{ $fund := .Params.raised_fund }}
{{ $fundCount := len $fund }}
#the result is empty
{{ $fund := .Params.raised_fund }}
{{ $fundCount := add $fund }}
#the result is error
ERROR 2018/09/01 14:17:40 Error while rendering "home" in "": template: index.html:11:7: executing "main" at <partial "singles/hom...>: error calling partial: template: partials/singles/homepage.html:184:17: executing "partials/singles/homepage.html" at <add>: wrong number of args for add: want 2 got 1
Total in 103 ms
ERROR 2018/09/01 14:17:40 Failed to rebuild site: logged 1 error(s)
Basically first store .Scratch in a variable
Then store in another variable the pages that have said parameter.
Then define the $fund variable to 0
Range through above set of pages.
Store the parameter in a variable and convert the string to a number using int
Store the above to a variable with .Scratch
Then outside the above context do the math.
PS. I doubt that the above can be done just with the variable overwrites introduced in Go 1.1. But please prove me wrong.
EDIT
Turns out you can do the above with the variable overwrites introduced in Go 1.11
@olikami your snippet needed int to convert the stings to numbers
Here is the working snippet (modified for my test project):
This one is now just outta interest, but why do you need to pipe to int? I thought if there aren’t any quotation marks it should automagically be seen as an int according to the toml-specs.