Is it possible to get the uri fragment from a url in eleventy to use as variable?
Example:
full url .../bibliography#citationKeyId
Then somewhere in a njk template:
{% set fragment = citationKeyId %}
{% if fragment = page.data.myvariable %}
-- do something --
{% endif %}
It sounds like it should be possible. There is a comment here about including window.location to the nunjucks context but I cannot find any info on how to do it!
You can't use window.location because that is a client-side API and you aren't using nunjucks on the client. You are using it in eleventy, which is a static site builder. (This is the same reason that the follow up comment to the one you mentioned rejects window.location because they are using gulp, which does a similar job to eleventy).
See the documentation: you can use page.url but it won't include the fragment because it hasn't been selected at the time Eleventy is rendering the page.
You'd need to use client-side JS to get that and, obviously, that would be too late to interact with Nunjucks (as processed by Eleventy), you'd have to deal with the DOM in the browser.