Prevent a resource file from being cached

I am trying to build a template playground where you could type go-text-template code in a markdown file and I could show the output on executing it. I have achieved this by a single page template with the following code:

<h1>Input</h1>
{{highlight .Content "go-text-template" ""}}
<h1>Output:</h1>
{{$content := .Content |resources.FromString "content.html"}}
{{$content = $content | resources.ExecuteAsTemplate "content.html" .}}
{{$content.Content | safeHTML}}

This does work and show the output correctly but not on live reload, as I think the resource file is cached and does not get reloaded. I have tried --disableFastRender flag but it doesn’t work. Is there a way I can force the re-render of this resource file on live reload. This is meant to be a learning tool and I don’t want to throw the students in the layouts folder just yet.

This sounds like you have the “template playground” running on hugo server. That is not really what this is built for. hugo server is for running your templates through a test website. Live servers don’t run on hugo server.

You could create a POST script that throws what is entered through hugo and shows the output, but I don’t think that will be a fast thing.

The post script will not be much different from the live server. I have found a workaround where I generate a new resource file on the fly by using the unix timestamp as the name of the resource. I don’t know if it will continue to work in the future but it does for now.

<h1>Input</h1>
{{highlight .Content "go-text-template" ""}}
<h1>Output</h1>
{{$name := (print now.Unix ".html")}}
{{$content := .Content |resources.FromString $name | resources.ExecuteAsTemplate $name .}}
{{$content.Content | safeHTML}}

It will.