Randomizing {{ range }} output

Hello everyone, i’m trying to figure out how to construct a file with a list of files in a subfolder.
which i will feed to ffmpeg later

I’m using this template in files.txt

{{range $indx, $val := .Files "music"}} 
file '{{$val}}'
{{end}}

to generate needed output.
It works perfectly, ffmpeg is able to process this filelist as input.

The question is:

IS it possible to shuffle order in which filelist is outputed on every request?

Thank you

I dont believe this is possible.

A scripting language server such as php, python etc would do this very easily.

I believe it can be done even with bash script and fastcgi, was just interested if it is somehow possible via caddy templates.
I think the problem is that .Files should be shuffled before ranging over them.
But as i understand there are no options to define a function that could solve this via template file.

You could put it in as a feature request. But it seems awful niche. Why do you want the files to be shuffled? Most people would want them in order…

Creating and uploading a lot of videos from gopro to youtube mixing audio from list of mp3 files, want background music in a random order for different videos.
As long as i understand it’s imposible to import go packages from template or add functions to FuncMap.
Not sure should this be added as feature request, but it looks like if it could be achieved this could add some interesting stuff to templates.

That sounds like a cool project. We could perhaps add a “generic” Shuffle function to the template actions.

Can’t find other reasons why “generic” shuffle should be there.
If there could be an option to extend FuncMap - that could be interesting.
But it looks like this is quite narrow niche, who would ever want to extend go templates functions?

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