[Zope] detect root.

Bill Anderson bill@libc.org
Sun, 21 May 2000 01:06:13 -0600


Bill Anderson wrote:
> 
> Sin Hang Kin wrote:
> >
> > Hello,
> >
> > I ask about how to detect root in the list and Got three answer:
> >
> > <dtml-if "_.len(PARENTS) == 1">
> >   We're at the root folder
> > <dtml-else>
> >   You can go up from here
> > </dtml-if>
> >
> > <dtml-if "title == 'Zope'">
> >
> > Title is Zope
> > <dtml-else>
> > No title not zope
> > </dtml-if>
> >
> > <dtml-if "id == ''">
> > root folder have not identity
> > <dtml-else>
> > there is id
> > </dtml-if>
> >
> > However, all of them fail working in virtual web with siteroot set. How can
> > I detect the root with or without siteroot?
> 
> perhasp you can be more specific as to what _exactly_ you need? What
> do you intend to do with he information. that has a bearing on how you
> get it, and what form the result is in.
> 
> Try this:
> <dtml-if URL2>
>   You can go up from here : <dtml-var URL0>
> <dtml-else>
>   We're at the root folder: <dtml-var URL0>
> </dtml-if>
> 
> This works because:
>  o URL0 is the root folder
>  o URL1 is the page you are looking: at it always exists.
>  o URL2 only exists if you are in a subfolder or sub-container
> 

Oops, reverse that. I wrote them backwards, and realized it immediatly
after hitting 'send'.
The root folder is the highest x in URLx, you start from where you are
(URL0), and count up.

URL2 still only exists if are in at least one level below the root,
though. If you are in the root fodler, URL0 wil be the page you are
on, and URL1 will be the root. URL1 will always exist in DTML (AFICT).
YMMV.