I have a simple page calling a partial. Inside the partial I want to loop over a folder:
~/wwwroot/img/sliders
For simplicity I have this code below for all intents isn’t searching the sub folder because I couldn’t even get this to work with the root wwwroot folder. It always shows a 0 count and no files not matter what I put in the vsFileSystem param.
{{vfsFileSystem(".") |> to => fs}} - tried wwwroot and all diferent variations
{{ fs.allFiles() |> sliders }}
{{ sliders.count() }} always 0
{{#each slide in sliders}}
{{ slide | textDump }}
I tried adding
WebHostPhysicalPath= MapProjectPath("~/wwwroot"),
as well as .UseWebRoot("wwwroot")
I’m not sure what I’m missing here. Any ideas, just a simple .net core app from scratch.
Sometimes late night coding doesn’t mix well with syntax. Thanks for the feedback here. Since using the script apps/pages I wonder if it is possible to add an overload for the to=> syntax.
{{ allFiles() |>= variable }} without having to add the to=>. Just an idea to consider although the explicit to is probably clearer with its intent and doesn’t break the front end compatibility.
The pipeline operator is a fundamental construct in #Script which was expressly added as an extension to #Script JavaScript Expression support because of the clarity it adds, especially in template generation, where it’s often included in template languages.
This concise syntax alleviates the need for requiring special syntax for other constructs like assignment, e.g. to and assignTo are simply just functions that you could implement yourself.
You’re asking to throw away the behavior of the pipeline operator (the most used an important construct in #Script) and replace it to be used as an assignment operator. No that is not possible.
FYI I’ve just added support for JavaScript variable declarations and assignment expressions in the latest v5.8.1 of #Script which will let you declare and assign variables with: