Render templates

def run(self, files, stack):
        "Render templates"
        # make stack available to all templates
        self.env.globals['stack'] = stack

        for filename, post in files.items():
            # render content first
            post.content = self.env.from_string(post.content).render(post.metadata)

            # check for a template field
            if "template" in post.metadata:
                template = self.env.get_template(post['template'])

            # or use the default template
            elif hasattr(self, 'default_template'):
                template = self.default_template

            else: # no template, so bail
                continue

            # at this point, we have a template, so render
            post.content = template.render(post=post)