Integration of snippets with macros variables #2612
-
I am a heavy user of snippets, where I embed config files in the docs like this:
But I also use the macros plugin to define global and local variables in my markdown to parametrize docs and avoid drift. For example:
The challenge is to combine the two. I would love to see if that is technically possible to do this:
where in the docs/test.yml the variable {{latest_version}} would have been substituted |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I'm not sure I understand. You mention macros, is this a specific package that offers you this functionality (I know there are probably a couple, so specifics are important). Ultimately, what this comes down to is a matter of which preprocessor runs first. If macros is run before snippets, then macros would be replaced before snippets handle the file insertion, but be warned, macros would probably only see the top-level snippet inclusion in a specific page. Snippets will grab nested snippets, but ultimately, every other plugin will only see the main document's content either before Snippets does its thing or the final result after Snippets does its thing, depending on when those other plugins are run. In your case, I get the impression that maybe your macros plugin is running before Snippets? Because it doesn't see the content in your Snippet. There are probably a number of plugins that all feel like they should be run before all other plugins, so then you can get into a war where one plugins changes to run earlier, and then someone with a specific use case goes, "oh, no I need to run mine even earlier". This can become subjective depending on your use case. Since I don't know what macros plugin you are talking about, I don't know when it runs, so I don't know the specifics. You would need to provide more information, but at least what I've described above lays a foundation for understanding the problem. Once you provide more info, we can talk specifics. |
Beta Was this translation helpful? Give feedback.
MkDocs Macros is not only run first but it would be run on the file before the Python Markdown process is even run. So Snippets won't even know anything about what macros replaced because everything is replaced long before Python Markdown and its plugins (which Snippets is part of) is even run. I'm unaware of whether MkDocs Macros even provides anything to Python Markdown afterward.
Honestly, if you need these things to work together and you are doing templating via macros, it may make sense to just include files with macros. I don't know how possible that is or not as I've never used macros.
The TL;DR of it all is that you could do something like below to pick a certain file to include, …