Dynamic expiryDate in archetype

You are currently processing the archetype so you cannot access the properties you set before (guess implementation and performance considerations.)

but you may store stuff in variables

---
{{- $mydate := "2024-03-25" }}
title: '{{ replace .File.ContentBaseName "-" " " | title }}'
date: "{{- $mydate -}}"
expiryDate: '{{- (time.AsTime $mydate).AddDate 0 0 30 | time.Format "2006-01-02" -}}'
---

which produces with hugo new content test.md

---
title: 'Test'
date: "2024-03-25"
expiryDate: '2024-04-24'
---

keep an eye on: [problems with date calculation:] mentioned in (AddDate | Hugo)
Calculate first day of current month and last day of current month - #4 by privatemaker

1 Like