Hi folks, I have a problem that I know should really be handled with layout files, but I got curious.
Is it possible to use if-else-end (and other conditions) when doing resources.ExecuteAsTemplate? It seems that every example out in the wild use this function only for fetching variables, but I would like to, for example, define two different versions of JS functions, based on the value of an article param. Is this possible?
You should assign different TARGET_PATHs (the second argument) for each param values. Similarly, if you’re using js.Build or toCSS, you should speficy different targetPath, then the page will load the corresponding JS/CSS file. BUT I don’t recommend doing that, I use this for separating the RTL and LTR styles only.
There should be much more simple way to do that, but I couldn’t provide help without knowing what extract you want to implement.
For example, you can generate some specified HTML block, then JS can access the page specified parameters and process, then you don’t have to hard code the params into the JS for each pages.
{{ if .Params.setting_a }}
(async function () {
await anotherFunction();
{{ else }}
(function () {
{{ end }}
// (rest of the function)
}
)();
I just tested it out, but only the async version got implemented, even for pages where setting_a is empty (false). Did I do anything wrong, or is this just not supported?