-
I have a project using mkdocs-material where I have a bunch of documents and I want to generate a custom index page that contains a table listing specific meta data provided in each of the documents. Let's say the document tree looks like this:
and each document has the the following (custom) meta data:
Now I want to generate an index page that contains a table with the rows: title, status, date, and keywords and each row represents one document displaying the respective meta data. I've tried to use the underlying custom_dir feature via: site_name: My Docs
theme:
name: material
custom_dir: overrides
docs_dir: docs in mkdocs.yml, then writing this template and putting it in overrides/adr_overview.html: {% extends "main.html" %}
{% block content %}
<h1>Architectural Decision Records (ADRs)</h1>
<table>
<thead>
<tr>
<th>ID</th>
<th>Title</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{% for page in pages %}
{% if page.meta %}
<tr>
<td>{{ page.meta.id }}</td>
<td>{{ page.meta.title }}</td>
<td>{{ page.meta.status }}</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
<table>
{% endblock %} and finally providing adr_overview.html in docs with
However, while the adr_overview is generated, the table seems empty. The for loop does iterate through all pages but apparently page.meta is not available for any of them. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Hello @venthur, I don't think this can be resolved using templates only, You have to aggregate the data yourself using a hook. To solve that you either have to preprocess the pages yourself, like the Blog plugin: The Blog plugin extracts the meta data and creates a separate Excerpt object for the Index pages, and then passes that into the custom template. Another way could be to let MkDocs process all of the pages normally, your index page would include a Personally, I would attempt the second idea if I would have to choose ✌️ |
Beta Was this translation helpful? Give feedback.
-
I think this is it! Thanks a lot, I learned a lot about the way mkdocs processes pages. |
Beta Was this translation helpful? Give feedback.
I think this is it!
page.page.meta
exists and seems to contain everything i need. So I think I can continue with my initial approach and don't have to use hooks in the first place.Thanks a lot, I learned a lot about the way mkdocs processes pages.