Suggested Training Exercise

Here is a training exercise that might help you build up your scripting skills once you have completed the basic exercises from your tutorial. The exercise is to build a template engine in Powershell. I actually did this as part of my own learning curve.

What is a Template Engine anyway? It’s a tool that combines a template with a data model to produce a series of expansions of the template. Each expansion uses some data from the data model to replace the variable items in the template. This is somewhat similar to the way a mail-merge function combines a form letter and a mailing list. An alternative name is Template Processor.

When I built my Template Engine, I actually didn’t know that word for it, even though I had built one in a different environment years before. I only learned the term Template Engine when I tried to share my effort.

My partcular engine uses data from a CSV file. That’s about the lowest form of structured data. It’s easy to reduce any other data model to a CSV file. The CSV file contains one data record for each expansion to be generated, and one field for each variable item in the template.
The template contains ordinary text and variable items. The variable items have the same format as powershell variables, because that is what they are. This isn’t necessarily the smartest choice, but it was real easy to implement. Keep in mind that this was a trainimg exercise.

SPOILER: If you just want to see my effort with going through the work of building your own, you can visit GitHub - DCressey/Expand-Csv: Expand-Csv is a simple csv template engine. It is easy to learn and easy to use. See Readme for more. · GitHub where I make a repository availalbe to the public.

I recommend to try to build your own. You might even try to imrove on my format for template veriables.