docs/content/en/functions/resources/FromString.md
The resources.FromString function returns a resource created from a string, caching the result using the target path as its cache key.
Hugo publishes the resource to the target path when you call its Publish, Permalink, or RelPermalink methods.
Let's say you need to publish a file named "site.json" in the root of your public directory, containing the build date, the Hugo version used to build the site, and the date that the content was last modified. For example:
{
"build_date": "2026-03-16T13:56:25-07:00",
"hugo_version": "0.158.0",
"last_modified": "2026-02-16T12:04:52-07:00"
}
Place this in your baseof.html template:
{{ if .IsHome }}
{{ $rfc3339 := "2006-01-02T15:04:05Z07:00" }}
{{ $m := dict
"hugo_version" hugo.Version
"build_date" (now.Format $rfc3339)
"last_modified" (site.Lastmod.Format $rfc3339)
}}
{{ $json := jsonify $m }}
{{ $r := resources.FromString "site.json" $json }}
{{ $r.Publish }}
{{ end }}
The example above:
dict functionjsonify functionresources.FromString functionpublic directory using the resource's .Publish methodCombine resources.FromString with resources.ExecuteAsTemplate if your string contains template actions. Rewriting the example above:
{{ if .IsHome }}
{{ $string := `
{{ $rfc3339 := "2006-01-02T15:04:05Z07:00" }}
{{ $m := dict
"hugo_version" hugo.Version
"build_date" (now.Format $rfc3339)
"last_modified" (site.Lastmod.Format $rfc3339)
}}
{{ $json := jsonify $m }}
`
}}
{{ $r := resources.FromString "" $string }}
{{ $r = $r | resources.ExecuteAsTemplate "site.json" . }}
{{ $r.Publish }}
{{ end }}