terminal-labs / lektor-jinja-content

Render Lektor content fields with Jinja2.
Other
11 stars 5 forks source link

field process ordering improvements #5

Open nixjdm opened 6 years ago

nixjdm commented 6 years ago

Problem:

It is not obvious in which order the fields are processed. In fact, it is currently unordered https://github.com/terminal-labs/lektor-jinja-content/blob/719829d047b5674075643840218fe60b4d4f07cc/lektor_jinja_content.py#L29 Being unordered has the consequence of unpredictable behavior if you're accessing other string-like fields from the same source object that also have jinja in them. For instance, if I have text fields:

depending on the order in which these are processed, text2 could be rendered as either

Possible solutions:

  1. Simply sort those dictionary keys, and document it in the readme. At least this way the behavior is predictable and consistent.
  2. Conjure up some way to allow users to set the order. A config file would be an easy way to supply a site-wide order. Something simple like "process body last". Alternatively it could be done per source object, perhaps pulled from an additional admin field that is basically the same as what could be in the config file, but that's quite a lot more power I suspect will almost never be needed.