Switch to using Nunjucks for templates and use a custom Wintersmith plugin that allows Nunjucks syntax to be used not only within templates but also within Markdown pages.