parse jinja templates on non-markdown pages #163
Replies: 12 comments
-
Welcome to this project and thank you!' first issue |
Beta Was this translation helpful? Give feedback.
-
I ended up getting this working and submitted a PR for the changes to the documentation page linked above |
Beta Was this translation helpful? Give feedback.
-
Thanks! Would this work for you? You may also use the Jinja2 include directive. |
Beta Was this translation helpful? Give feedback.
-
Hi, I have a similar problem. I have a YAML file (Jinja template) in the The file ( foo:
bar: {{ predefined_value }} (The variable Project structure: Is there a way to render variables on non-markdown pages? |
Beta Was this translation helpful? Give feedback.
-
You may use the Jinja2 include directive. Include renders the file included. |
Beta Was this translation helpful? Give feedback.
-
The problem is that I don't want to include the file, but leave it as it is and let the user download it using cURL for example. |
Beta Was this translation helpful? Give feedback.
-
I am not sure I understand what you want to do with your yaml file. Could you explain what the workflow is and, what problem you wish to solve? |
Beta Was this translation helpful? Give feedback.
-
I have two files.
The The problem is that the Jinja variables in the |
Beta Was this translation helpful? Give feedback.
-
So wou wish to render an external page, that will not be displayed? Where do you want the result to be stored? |
Beta Was this translation helpful? Give feedback.
-
@fralau Aha the include does seem to do the trick! My PR is unnecessary (though may still be handy for anyone who needs to include only certain lines and wants the variables parsed). @SadParad1se I think I understand what you are going for, but am not sure that this project is the correct target to accomplish that. What you are working on is not related to mkdocs, so I don't want to speak for the author, but that may be outside the scope of this plugin. |
Beta Was this translation helpful? Give feedback.
-
@spettinichi In the latest version of the doc, including external files has been included under Advance use (there is a problem with the display of the code examples, because the readthedocs environment seems to "eat" the include directives). @SadParad1se I agree that mkdocs-macros might not be the ideal tool for that, and you might need an external jinja2 engine (or, at worst, write your own; it's not very difficult). |
Beta Was this translation helpful? Give feedback.
-
Okay. Thanks to both of you. |
Beta Was this translation helpful? Give feedback.
-
I have a project where I store sample source files so users can clone the repository and run them as is, but I also want to embed them into markdown pages for usage with mkdocs as well. I followed this to be able to embed the source files https://mkdocs-macros-plugin.readthedocs.io/en/latest/tips/#i-would-like-to-include-a-text-file-from-line-a-to-line-b
This works great, except that variables in the source files will not be evaluated and replaced.
I don't see a way to accomplish this. I believe I will have to add variable parsing within my python file, but this plugin does not have a function to pass a variable and have it evaluated by jinja rules and return the result, so it seems I would have to duplicate much of the functionality of this plugin which is not ideal.
Is there something I am missing, or is this something of interest to include into the project?
Beta Was this translation helpful? Give feedback.
All reactions