Modify front matter via code

Is there a way to modify front matter, say the “weight” param, without opening the .md file and manually editing it?

I tried things (in a template file) like:

{{ .Params.weight := .Params.weight + 1 }}
{{ add .Params.weight 1 }}

… And both didn’t work as I naively expected.

Hi there,
I’m suprise the second line does not output what you expect… :thinking:
Anyhow, you cannot modify the .Param per say.
But you can store its new value in a variable for later use.

{{ $weight := add .Params.weight 1 }}
That Weight: {{ $weight }}

For more complex usage of variable storing/getting/adding see .Scratch

Thanks! The second line actually outputs the result - just prints it out, without affecting the original value in the front matter.

I guess I haven’t fully grasped the “static” part about static site generators…