|
Well, unless someone objects I don't see any reason not to talk about the conditional sections here. I also limited the section names to 32 characters, that was for two reasons, one was that I have what some might call an obsession with using "even" field lengths, by even I mean 1,2,4,8,16,32,etc. but mostly I chose 32 because of how I store the sections and variables. I use two dynamic arrays, one for the sections and one for the variables what each array element actually contains is a pointer to a data structure containing the section/variable name and a pointer to the contents of the section or variable. Actually for the section the pointer is to a linked list of data structures that point to variable data structures. This means that when I do a wrtsection I only have to do the one lookup to find the section, and then I just follow the linked list to output the contents of the section including any variables in it. The conditional sections are defined within an existing section of the template. An example would be something like this. /$ReportHeader <h1> /?SELECT /%month%/ = 00 //00 is the most recent month Most Recent Report /?WHEN /%month%/ = 99 //99 means Year to Date Year to Date Report for /%year%/ /?WHEN /%month%/ >= 1 AND /%month%/ <=12 Report for /%month%///%year%/ /?OTHER // the OTHER conditional section is optional. Invalid date selected for the Report. ?/ </h1> $/ /* I don't remember if the original CGIDEV had the ability to use comments or not but I have it in mine. I can specify // at the beginning of a line to comment out that line or I can use /* and */ at the beginning of the line to comment out multiline sections, these comments are not output to the browser. I also don't remember if CGIDEV had section ends but mine does a section will end at either $/ or at the next /$, anything between $/ and /$ is ignored. */ I also allow the conditional sections to be nested, so you could have something like this /?SELECT /%somevar%/ = 0 some html /?WHEN /%somevar%/ = 1 blah blah blah /?SELECT /%someothervar%/ = A some conditional html (only displayed if somevar = 1 and someothervar=A) ?/ yada yada yada /?OTHER html displayed if none of the above conditions are met ?/ Each conditional can be compound, so ANDs, ORs, and parentheses can be used in the conditional statement. As far as what I use them for, the first example is what I usually use them for. Where the output is dependant on a variable, but does not necessarily include the variable. I have also used them for things like making negative values red and positive values black. Mostly they are another way to separate the presentation from the business logic, the CGI program just reads and outputs the data, the template determines how it looks. They also decrease the number of times you need to modify the cgi program in order to change how the web page looks. The only draw back to using the conditional sections is because of how I implemented them. When I read in a template I parse the template into the sections and I break the sections into blocks of text separated by variables, comments, and conditional sections. This means that writing a section is extremely fast. Unfortunately when I did the conditional sections I didn't parse them at the beginning. Instead when I get to a conditional section I parse and evaluate the conditional statement during the write. This means that if you have a conditional section surrounding a single cell of a report, and if it has several complex conditions, it can slow the output process significantly. Someday I want to update the program so that it parses the conditions into a tree of linked data structures as they are read in and all I have to do is follow a series of pointers and evaluate the results. But I haven't had the time to do it yet. Joe Lee >>> cozzi@xxxxxxxxx 10/21/2004 15:49:55 >>> Yes, that's why I wrote CGILIB with the xTools. It doesn't have the scaling limitations that CGIDEV2 had. As long as you stay under 16MB of HTML being sent at once, there are no practical limitations. I do limit the section names to either 32 or 64 characters (can't remember which it is at the moment), but you can have as many of them as you want. I would like to hear more about your "conditional sections" including what you use them for, and how you use them. Perhaps offline would be better if others aren't interested. As to your 1993... that's perfect. In my CGI RPG classes, I have a line that I often use: "Many long-time HTML coders, and by long-time, I mean someone who started using HTML before 1997... seem to prefer Windows Notepad as their HTML editor of choice." That line usually gets a good laugh, but as you have indicated... there's some truth to it. -Bob -----Original Message----- From: web400-bounces@xxxxxxxxxxxx [mailto:web400-bounces@xxxxxxxxxxxx] On Behalf Of Joe Lee Sent: Thursday, October 21, 2004 5:30 PM To: web400@xxxxxxxxxxxx Subject: RE: [WEB400] Browser tries to download program Well, I suppose I could be considered experienced. I think I wrote my first web page in 1993. Though I suppose it might be sort of weird that I have never put together my own personal website. I wouldn't say that there is anything "wrong" with using the noname/*top sections. The reason that I wouldn't use them is that I like the consistency of having every section named. Granted in this case there would only be one unnamed section, but I still prefer to avoid using a mix of implied and defined section names. I'm also not sure that it would work with my version of CGIDEV. We kept running into problems with not enough sections or variables being available, so I rewrote it using dynamically allocated arrays to store up to 32K sections and variables, and I don't think I made provisions for the "noname" section. I also added several capabilities that weren't available at the time, this was several years ago, such as loading from the IFS, being able to load several templates at once, and "conditional" sections which are like a select statement and allow you to output portions of your section based on the values of your variables. Joe Lee
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.