Re: [Rest2web-develop] Section headers
Brought to you by:
mjfoord
From: Michael F. <fuz...@vo...> - 2006-08-05 13:27:42
|
martin f krafft wrote: > also sprach Michael Foord <mi...@pc...> [2006.08.05.1305 +0100]: > >> martin f krafft wrote: >> >>> also sprach Michael Foord <mi...@pc...> [2006.08.05.1158 +0100]: >>> >>> >>>> Yes indextree['parent'] is always None. >>>> >>>> >>> Ok. >>> >>> >>> >>>> I *think* I see what you want to do. You want a single index page >>>> which only shows pages from the selected section. I could probably >>>> achieve that with javascript, but I wouldn't know how to do it >>>> with CSS. :-) >>>> >>>> >>> No no, much easier. I simply want a list of categories (let's not >>> call them sections) as defined in the root, to show up on all pages >>> of the site. I want one of those categories to be hilighted, >>> depending on where we are in the site. >>> >>> Pseudocode: >>> >>> def current_url_matches_category(page, cat): >>> // ... >>> >>> print '<ol id="globalsect">' >>> for cat in indextree['categories']: >>> if current_url_matches_category(page, cat): >>> print '<li class="current">' + cat['link title'] + '</li>' >>> else: >>> print '<li><a href="%s">%s</a></li>' % (cat['base_url'], >>> cat['link_title']) >>> >>> >>> >> Hmm... on reading your pseudocode a bit more carefully.... :-) >> >> You want every 'category' to have a 'base_url' as well. >> >> This isn't something that is really directly available in rest2web - you >> want global categories and information available to every page. >> >> You could then set the category for each page in a uservalue. >> >> How about if I add some 'globals' to rest2web that are available in >> every page? >> > > This would be a nice feature to have. Think site_title: > > <title><% title %> - <% site_title %></title> > > I have just added 'globalValues'. You could now do something like : try: site_title except NameError: site_title = globalValues['site_title'] else: globalValues['site_title'] = site_title Which is perhaps a little ugly. :-) The better way of achieving this is to provide uservalues in your site config file. These are already available to every page. >> You would set these in the top level, and could use them from every >> page. Your code would look something like (in your template) : >> >> <# >> >> # This code will only be executed once >> # It could be kept in an external module and imported >> if not categories in globalValues: >> categories = {} >> categories['category 1'] = {'base_url': '/url1', >> 'link_title': 'link title 1'} >> categories['category 2'] = {'base_url': '/url2', >> 'link_title': 'link title >> 2'} >> globalValues['categories'] = categories >> >> #> >> >> Feel free to suggest a better name than globalValues. :-) >> >> You could find a better way of setting up the categories than hardcoding >> them into your code, based on the other values available to you. *You* >> still have to decide which is the base url for your categories though. >> > > Well, I think that subdirectories would make perfect sense. > > Now I have to figure out how to use the indextree structure: > > - how do I get a page's uservalues? In an earlier mail, you told > me to use indextree['namespace']['myvalue'], but there is no > item 'namespace' in the indextree structure. > I thought I suggested (I should have done) : sections['section name']['pages'][pageIndex]['namespace'] or : for section in sections.values(): for page in section['pages']: namespace = page['namespace'] This only gives you access to pages in the current directory though., and index pages of the directories below. > - how do I get at other restindex values? For instance, if > I needed to read a page's page-title, how would I do that. > > You can't access the restindex or uservalues of pages through indextree. Every page in indextree has a 'link-title'. If this hasn't been explicitly set in the restindex of a page, it defaults to the page title. What other values do you need access to ? Fuzzyman http://www.voidspace.org.uk/python/index.shtml >> If you then set a 'category' uservalue in each page, your pseudocode >> becomes : >> >> <# >> >> print '<ol id="globalsect">' >> for (catName, cat) in globalValues['categories'].items(): >> if category == catName: >> print '<li class="current">' + cat['link_title'] + '</li>' >> else: >> print '<li><a href="%s">%s</a></li>' % (cat['base_url'], >> cat['link_title']) >> >> #> >> >> How does that seem ? >> > > (I am not trimming the reply because this goes out to the mailing > list). > > |