Templating JS file

Hi guys,

I did some research, but only see old posts with possible solutions that don’t work…

How do I create a JS template file?

thanks…

Several ways, I guess, but you could use resources.ExecuteAsTemplate.

thanks for your reply. Can you give me an example what would work the best? It’s hard to figure out…

I want to create an include.js with all the latest posts in it. And include that in each post…

i put temp-include.js in assets/js

and this code in a random .md file:

{{ $templateStyle := resources.Get "js/temp-include.js" }}
{{ $style := $templateStyle | resources.ExecuteAsTemplate "js/include.js" . }}

can you please tell me the most simple way? this is the last piece of my website puzzle… :slight_smile:

i have an .js template file with the latest 15 posts in it. but it wont create a file in the public dir…

it’s working already. i needed to put the URL to the JS file also in the .md file

1 Like

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