![]() |
indextree and thispageRepresenting Site Structurerest2web provides your templates with three variables that give you information about the site structure. The first is called sections. This gives you information about all the pages in the same directory as the one that is being rendered. See the templating page for the description of that data structure. The other two variables are called indextree and thispage. indextree is a data structure that represents more of the whole site than sections. thispage is a pointer to a specific part of indextree. indextree itself represents the top level page. It has members representing the pages inside the top level directory. Any index pages for sub-directories will be represented here, and will themselves have pages. Because of the order that sites are processed in, any page can know that every directory above it will have been fully processed. This means that indextree can be used to construct 'sidebar' type links that look a bit like the following : (root directory) index page <- indextree | | section1 | (a sub-directory) | section 2 - Index Page | | | | section 3 | | sub-section 1 | | section 4 sub-section 2 (another sub-directory) | sub-section 3 - Index Page | | **This Page** <- thispage | Another Page | And Another One This allows a sidebar that is a set of links to all the sections above the current page. It doesn't yet allow you to know what pages might be in section 3 or section 4 of the root directory - but it would be unusual to need to put that amount of links just in a sidebar [1] ! You can see an example of using sections for sidebar information in the rest2web docs. The test site is an example of a site using indextree for the sidebar. You can use the standard function sidebar to generate these sidebars from indextree. The actual data structure indextree is a dictionary that represents the index page for the top level directory. The dictionary contains links to dictionaries that represent the other pages and indexes. indextree is actually just part of the whole tree - it only contains the branches needed to get from the root directory to the current page that is being rendered. The dictionaries in indextree all follow the same pattern [2] and contain the following members :
As well as indextree, templates also have access to a value called thispage. thispage is an entry in the indextree structure, but it points to the current page. If you like indextree is the top of the tree, and thispage is the bottom. Note Pages that have 'include' set to 'No' aren't in indextree. For those pages the value thispage will be None. All string values in the indextree structure are encoded using the appropriate encoding for the page being rendered (as determined by the value final_encoding).
Return to Top |
||||