Search code examples
jekyllliquid

How do I detect the current page in a Jekyll tag plugin?


I have a Jekyll (Liquid) block plugin and I'd like to detect what the current page is. I see that a context is passed into render, and that I can retrieve the current site object as context.registers[:site]. However, attempts to get the current page as context.registers[:page] fail.

The problem I'm trying to solve is to create a simple block plugin to detect if the current page is the page mentioned in the tag, and highlight it.

Any tips would be greatly appreciated.

Thanks!


Solution

  • Turns out we can also do this like:

      def render(context)
        page_url = context.environments.first["page"]["url"]
    

    Which is not obvious but it doesn't require patching the code.