How to restore folder default behaviour to forward to /index

So the default folder behaviour is to forward to /index… I have some folders that contained content, but now it has been removed and the content sitll displays.

Is it possible to restore the default folder behaviour that forward a user to /index if they go to the folder root? Maybe a code snippet?

The default behaviour will display the first listed page within the folder if the folder description/content is empty (so not necessarily the ‘index’ page).

This should all still be working by default. The default code in the Folder detail layout is:

{% if this['description'] != "" %}    
    {{this['description']}}
{% else %}
    {% capture indexPage %}{% component type:"module", source:"Page", layout:"Page Detail", filterBy:"parentid", filterValue:"{{this.id}}", limit:"1" %}{% endcapture %}
    
    {% if indexPage == "" %}    
        {% component type:"module", source:"Page", layout:"Page Detail", filterBy:"name", filterValue:"404" %}       
    {% else %}
        {{indexPage}}       
    {% endif %}
    
{% endif %}

Note, though that the 404 page call here doesn’t actually work (remains from an older version of the CMS).
You can however, adjust the logic here for your own needs.

Also, I’m not 100% sure what you meant Alex by:

I have some folders that contained content, but now it has been removed and the content sitll displays.

Do you mean the folder contents (description area) or the contents of the folder (pages within)?

As an example of customising this logic, I’ve implemented the following to display a page within the folder that has the slug of /index, else a fake 404 page/message:

{% 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 %}
1 Like

@Adam.Wilson Thank you for your response. I’m sorry for the late reply. I picked up this issue in the development of this current site and only now have been having time to loop back around. I like your snippet a lot better than the default in that it always picks up the index page (expected behaviour).

Regarding:

Blockquote I have some folders that contained content, but now it has been removed and the content sitll displays.

At the time it seemed to me that If I had added content to a page folder, and then remove it, I would no longer see the index page. It could be that I just wasn’t fastidiously clearing the page and leaving behind some spaces. In any case I can’t replicate now.

I guess this will use the metadata from the page folder and ignore the metadata on the /index page, as it’s just grabbing the description field. Have you come up with a workaround for this?
Is it possible to update the page folder meta fields with the /index meta fields?

I think you could create an overriding Liquid variable from the index page item and pass it back to the template.
So based on my snippet provided in your other post (Possible to automatically fill SEO page title and SEO canonical? - #2 by Adam.Wilson) you’d want to override the pgOGelsSEOelsName variable for example.
It’s a bit of a complex and confusing setup though :slight_smile:

At the time it seemed to me that If I had added content to a page folder, and then remove it, I would no longer see the index page. It could be that I just wasn’t fastidiously clearing the page and leaving behind some spaces. In any case I can’t replicate now.

I think this is a case of empty vs null values. So your previous code might have been doing something like:

{% if this['description'] != '' %}

rather than:

{% if this['description'] != null %}