Displaying /folder/index content when going to /folder

I was using a snippet to grab the /folder/index content when a user goes to /folder (note: I want to grab /index specifically and not just the first random file in a folder). This no longer seems to be working for me. Has anybody else found a workaround for this?

Here is code snippet I was using previously:

{% if this['description'] != null %}    
{{this['description']}}
{% else %}
{% capture indexPage %}{% component type:"module", source:"Page", layout:"Page Detail", filterBy:"url", filterValue:"{{this.url}}/index", limit:"1" %}{% endcapture %}
{% if indexPage == null %}    
    <p>404: Page not found.</p>
{% else %}
    {{indexPage}}       
{% endif %}
{% endif %}

Hi @Alex_B_Centrifuge. I’ve tested your code and it’s working fine on my site.
Where is it failing for you? Is it not retrieving the Index page and you are seeing just the 404: Page not found. text.
Or are you not seeing anything output?

Hi @Alex_B_Centrifuge, could you give me your website so that I can help you?

I’m just seeing the template with no content. No 404 message either. In fact the default snippet isn’t working either. Must just be another bug.

@Irene I have a ticket in for this already: 1398

@Alex_B_Centrifuge, we’ve replied to you in the support ticket. It seems to be some specific case.

I’m getting a Recursion error when I use this on the page folder. What did you set to make this work? Thanks

Hi @g.davis
I’m not sure why you’d be getting a recursion error, but the above code works for me with one adjustment.
Since the capture, if empty, actually returns a space so the IF statement checking for a null value will not work.
To fix this, I strip the captured variable first (to remove any whitespace), like this:

{% assign indexPage = indexPage | strip %}

So the full code would be:

{% if this['description'] != null %}    
{{this['description']}}
{% else %}
{% capture indexPage %}{% component type:"module", source:"Page", layout:"Page Detail", filterBy:"url", filterValue:"{{this.url}}/index", limit:"1" %}{% endcapture %}
{% assign indexPage = indexPage | strip %}
{% if indexPage == null %}    
    <p>404: Page not found.</p>
{% else %}
    {{indexPage}}       
{% endif %}
{% endif %}

Hopefully, that resolves your issue.
If not, double check you have a sub-page with the slug of /index (or whatever slug you are checking for).
And perhaps paste your code here so we can review it along with a URL where we can see this error if possible (or a screenshot).