this file contains "tagsof the form /***where the data is an optional single word and the directives areincludecopy the contents of another file here variableinsert the contents of variable here loopoverrepeat the contents of the loop for variable that is list endloopsignal the end of looped text loopvarinsert single value from the list being looped over this template will render different page depending which variables are passed into it these variables will be passed in from so-called context file this will be encoded as json object with keys representing the variables in question my context file might look like thisbut you would derive your own"name""dusty""book_list""thief of time""the thief""snow crash""lathe of heavenbefore we get into the actual string processinglet' throw together some object-oriented boilerplate code for processing files and grabbing data from the command lineimport re import sys import json from pathlib import path directive_re re compiler'/\*\*\ *(include|variable|loopover|endloop|loopvar) '\ *([*]*)\ *\*\*/'class templateenginedef __init__(selfinfilenameoutfilenamecontextfilename)self template open(infilenameread(self working_dir path(infilenameabsolute(parent self pos self outfile open(outfilename' '