Forum OpenACS Development: Re: A Model for the Navigation Bar

Collapse
Posted by Jim Lynch on

Once I have all this in place, how do I go from page to page? Remember that ALL of the pages (under this particular scheme) except for the www/index page will receive a value for context_fragment.

One way to get to a different page is by a link. I have gravitated to using export_vars to create links, and the links have their own ways of passing variables, and the knowledge of how it's done is all in export_vars, and I don't really have to worry about it... all I have to do is put the name of a variable in the appropriate place, and export_vars will either add what's needed to pass it, or fail to include it -- if it's found to be unassigned.

For example, say there is a preferences page (www/preferences.tcl, www/preferences.adp), and there is a list of things on the page. For each item in the list, we want to be able to go to a page detailing that thing, and we want to be able to delete it. Lastly, we want to be able to go back from the preferences page, to where we were when we hit the preferences button or link.

As usual, the preferences page received the value of context_fragment that represented the previous page, and we have the appended values in context and new_cntxt_frag, so the infrastructure is all set up.

First, let's take the detail page, which we'll call one-thing(.tcl and .adp). We have the list on the preferences page because we made a database query that got us the thing_id, and a few other things for display purposes.

for each item in the list, we can get the detail page url using this call to export_vars:

set detail_url \
    [export_vars \
        -base one-thing \
        [list \
            thing_id \
            [list context_fragment $new_cntxt_frag]]]
which we can put into an <a> tag using some repeating structure which also writes out the list of things. Here, we want to pass the value of context_fragment that represents the preferences page, because we want a link in the navigation bar that will take us to the preferences page. This all has the effect of adding a link to the navigation bar, so it appears we're going deeper, so the page flow is preferences -> one-thing. And since the one-thing page has the thing_id variable passed to it, we can query the database for the row that holds the data for the thing, and using the one-thing.adp, we can show the data.

Next: Going to a page that takes an action, then redirects back: deleting a thing