Can you access data from individual data files, rather than storing data in the mkdocs.yml config? #4862
-
Apologies in advance for the beginner question. I have looked through the documentation, and have stumbled my way to a partial solution, but it would be really helpful to get some steer/guidance on this: I would like to create a simple image gallery, and have set up a template that extends So far, the closest I have come to the solution I have in mind is the following: {% extends "base.html" %}
{% block content %}
{{ super() }}
{% for item in config.images %}
<h1>{{ item.title }}</h1>
<figure>
<img src="{{ item.url }}" style="width:100%">
<figcaption> {{ item.caption }} </figcaption>
</figure>
{% endfor %}
{% endblock %} This works, but it requires me to store the data in the mkdocs.yml config, which is not ideal: site_name: Test Site
theme:
name: material
custom_dir: overrides
images:
- title: "Image Title 1"
tags:
- tag 1
- tag 2
image_url: "https://example.com"
caption: "An image caption."
- title: "Image Title 2"
tags:
- tag 1
- tag 2
image_url: "https://example.com"
caption: "An image caption." A couple of questions:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I guess you might be able to use MkDocs configuration inheritance mechanism.
AFAIK, only the path must be correct.
If you define your configuration in |
Beta Was this translation helpful? Give feedback.
-
Thanks, @squidfunk. The first suggestion of configuration inheritance sounds like a good quick fix. But I think your second suggestion of using the macros plugin may be a better longer-term solution. I'll have a play around with them both and see how I get on. |
Beta Was this translation helpful? Give feedback.
I guess you might be able to use MkDocs configuration inheritance mechanism.
AFAIK, only the path must be correct.
If you define your configuration in
mkdocs.yml
, it will be global, so that's the way to go. Other options are using the macros plugin (possibly also global), or putting your data into front matter to scope it to a specific page.