Get page.url from inside a nested include

I have an include called audio.html which is added to a post.
I have a page of all posts which is /episodes/
and I have the latest post appearing on the homepage.

I want to get the current page url inside my audio.html include to modify the content based on whether the post is appearing on the homepage or on the episodes page.

I’ve tried {% if page.url == "/index.html %} but this always returns the url of the post, not the page it’s currently appearing on.

Can I set a variable in my index.html file (homepage) and read it in my audio.html include?

I hope that makes sense.

I think you are looking for this guide: https://jekyllrb.com/docs/includes/. There is a section how to pass parameters to includes.

Hope that helps.

1 Like

This helped and its now working.
I had to move my audio.html include out of my individual posts and put it into the episodes listing page. I then passed the individual posts in as so

{% for post in site.posts %}
  {% include audio.html page=post %}
{% endfor %}

Now in my audio.html include I’m able to do

{% if page.url == "/" %}
// Homepage specific stuff
{%endif%}

Result. Thanks
:+1:t4:

1 Like

Anytime! :smile: :clinking_glasses: