Forums / Setup & design / How to get grandparent folder

How to get grandparent folder

Author Message

RW Wood

Sunday 21 September 2003 1:59:21 pm

I've figured out that I can produce a list of folders within the current folder with the following code:

{let folder_list=fetch( content, list, hash(parent_node_id, $node.node_id, sort_by, array( array( priority ))))}
{section name=Folder loop=$folder_list}
<a class="small" href={concat( "/content/view/full/", $Folder:item.node_id,"/" )|ezurl}>{$Folder:item.name|wash}</a><br />
{/section}
{/let}

However, once I get to the bottom of the folder tree, I get a list of articles, which is fine, but if I then open one of those articles, the list is empty. What I'd like to have is that the same list of articles stays there when any one of them is open. Is there an easy way to do this with a {section show} and {section-else} or some other solution?

Thanks.
RWW

Bjørn Kaarstein

Monday 22 September 2003 1:51:35 am

When you're viewing your folderlist, I assume you have written an override for your folder class, displaying your list of articles.

When you switch to viewing an article, instead of a folder, you'll be using another template to show your article. Within that template, you could reproduce your article listing in addition to displaying your full article. I think you can fetch (parent_node_id, $parent_node.node_id) or something like that.
Just use the |attribute(show) to check what you can access.

Regards Bjørn

RW Wood

Monday 22 September 2003 7:27:27 am

I haven't written an override because this code is part of the pagelayout.tpl for my design. The purpose is to have a list of folders appear in the left column without any details about the folders. The code in my original post does that quite well.

I also know that if I change $node.node_id to $parent_node.node_id, I'll get a list of what's in the parent folder, which is what I want when I'm viewing an article itself and not a list of what's in a folder.

My problem is how to I structure the {section} and {section-else} statements so that essentially ezP is told "If you are displaying a folder that has contents, either sub-folders or articles, show a list of those folder or article titles. But if you're displaying an article, show a list of all the articles or sub-folders that are in the folder the current article is found in."

In other words when I've reached the bottom of the folder tree, using the above code the list would be empty, using the $parent_node.node_id code, the list would be populated with a list of articles and sub-folders, one of which being the current article.

If {section} and {section-else} is not the way to accomplish this, what is.

Thanks.
RWW

Bjørn Kaarstein

Wednesday 24 September 2003 2:06:24 am

Could you try to use a switch/case statement based on class?

Something like this: (I assume folder is class 1 and article class 2)

{switch match=$node.object.contentclass_id}
{case match=1} {*folder*}
List articles from current folder
{/case}
{case match=2} {*article*}
List articles from parent folder
{/case}
{/switch}

If all articles is on the same depth, you could also check on $node.depth

Regards Bjørn