Simple Counter with Scratch?

I’m trying to create a simple data dashboard on my Hugo site that will simply add or subtract 1 from a number once a day. For example:

  • Days until final paper due: N-1
  • Days since my last haircut: N+1

I was thinking of making a bash script that changed the variable each day, but I thought there might be a solution with .scratch. Has anyone done this? Any ideas or pointers appreciated.

{{ $var := 100 }}
{{ $var = add $var 1 }}

And you can have a look at this hugo theme for javascript counter :

1 Like

Thank you. But consider me a complete .scratch noob. How would I set that up?

No need .scratch.

Now you can use := for init variable and = to update it.
Try my code

@divinerites is right – Scratch still has its use, but it was added to Hugo before Go template got “variable reassignment support”, which made it’s prime use case obsolete.

Ok, just don’t know where to save this code and how to declare it. Apologies.

No worries. But my advice would be to start with the hugo basics and do a hello page first. Then you can build above that.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.