tests-always-included / mo

Mustache templates in pure bash
Other
563 stars 67 forks source link

Include/Import files in loop #24

Closed jradek closed 5 years ago

jradek commented 5 years ago

Hi,

I try to import/include files within a loop, like this.

I tried to debug the source code, with my limited knowledge about bash scripting, and the error seems to be in function moParse around line 657 during the call of moPartial. Inside moPartial, the local variable moFilename is assigned to .. So the actual content of the current iteration, i.e. file1.txt was not passed.

I'm not sure, if the thing I try to accomplish is a limitation of bash or an actual bug in mo.

Thanks, JR

fidian commented 5 years ago

This isn't really a limitation of Bash. The error could be seen as a bug in mo, but the real problem is that your use case falls into the category of logic, which Mustache templates do not support. If you want to demo this yourself, you could start with this demo, which uses the JavaScript library: https://codepen.io/fidian/pen/dwKGWV

This is not the right way to use a mustache template. You may want to consider writing a function to do the same thing. There's an example named demo/function-for-advanced-looping that illustrates the function. You'll need to source mo into the environment so it can access the functions, which is why the example says . ../mo.