Included markdown file in content files
See original GitHub issueThis was originally mentioned in the comments of #439, and later I mentioned it again in #532. This is a different topic though, so it gets its own issue.
There is a common desire to in some way include a markdown file by reference in a content field of a contents.lr
So instead of a markdown body
field whose section in a contents.lr
looks like
body:
**Some Markdown here**
and here.
The value for the body field would point to an external .md
file. The ability to separate out a (large) field’s value can make it easier to maintain that field (it could be outside of a project repo, it could be “hot swappable”, etc), and break apart a large contents.lr
into more conceptually digestible chunks.
This could be done for a variety of different field types, and potentially arbitrary field types, though I think it makes the most sense for multi-line string-like types.
So how do we accomplish this? An option is to allow for attachments of other various types, detected by file extension, and then allowing the ability to select attachments via the CMS. Another option is to add a way for someone to input a relative path in the CMS / contents.lr
that can point to any file. Do we let users define file types in models? Do we force them? There are lots of ways this could be done and discussion is welcomed.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:7 (5 by maintainers)
Top GitHub Comments
I’m not talking about treating a contents.lr as a markdown file, but more like the comment that follows the one you cite - including an external file by reference in an contents.lr. My question is, what method is best?
I realized that one way this could work is by virtue of my plugin Jinja Content. For instance, with this, you could actually reference any other file and pull it in with a standard jinja include. E.g.
This nearly works right now, but I think Lektor would need a couple small updates to https://github.com/lektor/lektor/blob/master/lektor/environment.py, and the plugin would need to add some paths to support “templates” being in the contents dir.
Some points about this approach:
If that’s the route we take, Lektor itself would only be changed to allow the functionality by the plugin, and the plugin’s doing most of the work.
Yes, it shouldn’t be auto-magic. I was thinking it could be a global setting, or per-field:
Then we’d have a single content-type for any given format, and the only change needed to the existing types would be to give them a set of extensions to look for where appropriate. Or (also) make it explicit in the model: