On Sun, 16 Apr 2023 at 21:55, Paul Moore <
p.f....@gmail.com> wrote:
> To use BODY_END (or EXTRA_HEAD) I'd need to write a plugin in Python, wouldn't I? Or can I set that in a template shortcode as well? Although I'm getting the impression that doing this *without* a plugin may be more difficult than it's worth...
You can’t do that from a template shortcode.
> Alternatively, is there a way to say "if the page/post has a particular value in its metadata, add the following to the page HTML somewhere (header or body end seem like reasonable options)"? Basically, I'm thinking of a custom equivalent to the `has_math` metadata value.
You could try doing the same thing math_helper.tmpl does in your
site’s theme/templates (the math_scripts_ifpost(s) functions are
called from other templates where math might be needed). has_math is
an attribute on post objects; your custom meta field won’t be, but you
can still access the metadata dictionary with
post.meta['lang'].get("has_fancy_js_library"). You could also expose a
custom Python function in GLOBAL_CONTEXT to make this easier (this
might be necessary if you’re using Jinja2, which doesn’t allow
arbitrary Python in templates.)