-1

I'm trying to a add a variable into the following:

eleventyConfig.addPassthroughCopy({ "random-folder/img": "subfolder/img" });

What I've tried:

var directory = "random-folder";
eleventyConfig.addPassthroughCopy({ directory + "/img": "subfolder/img" });

However this does not work. Help hugely appreciated. The path to the left of the : is the source and to the right is destination. More information on the structure here if needed.

morgyface
  • 368
  • 1
  • 9
  • Hey @Quentin I can appreciate the need to remove duplicate questions, but do bear in mind, a JS novice like me would never have identified a solution to my issue in the answer you've specified. My question also relates to 11ty specifically. Looking at the answer you believe my question duplicates, I can see the similarity, but it's still not obvious. Do remember Stackoverflow is used by people learning and growing, they're not all experts and whilst something might look like a duplicate to you, it isn't when you take into consideration skill level and context. – morgyface Mar 26 '20 at 11:18

1 Answers1

0

You just need to wrap property name in brackets like here:

var directory = "random-folder";
eleventyConfig.addPassthroughCopy({ [directory + "/img"]: "subfolder/img" });
Marek Szkudelski
  • 1,102
  • 4
  • 11