On Sun, 16 Apr 2023 at 21:55, Paul Moore <[email protected]> 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.)
--
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16
--
You received this message because you are subscribed to the Google Groups
"nikola-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nikola-discuss/CAMw%2Bj7%2B1fXLah9EqHu9M4MmkM6NSqS%3DV2-3wEUm39hXu9y6SUg%40mail.gmail.com.