docfx

Using tags in DocFX markdown frontmatter / YAML header


I have a DocFX site with a number of pages. I would like to include tags at the top of each page via custom template, and I'd like for authors to be able to add tags in the YAML frontmatter, e.g.:

---
title: My Page Title
tags: tag1;tag2;tag3
---

I would then like to be able to access those tags as some sort of array and process them when generating the HTML output.

I've read the docs here which suggests that I can add a schema.json file somewhere and this will automatically detect items in the schema. What I can't work out is how to access the YAML frontmatter in my template when generating the output.

If I need to write a custom .NET plugin to do this then that isn't an issue, but I believe I should be able to access these properties in the template somehow.

Any guidance at all would be very gratefully-received!


Solution

  • I managed to eventually work this out.

    In my custom template I have a conceptual.html.primary.tmpl file which provides access to the frontmatter:

    <div id="tags">
      {{#tags}}{{tags}}{{/tags}}
    </div>
    

    Obviously I now need to process the tags, but I now get HTML produced as expected from my .md files:

    <div id="tags">
        tag1;tag2;tag3
    </div>