![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
ClariCGI Template Predefined Variables
When a ClariCGI template executes, several predefined variables are created or updated for use by the template.
General VariablesAll the configuration variables are available as variables to templates. Indeed, extra variables can be put in the ClariCGI configuration file to be available to templates as you see fit. Variables defined in the configuration file are permanent and may not be changed by templates. If you want a template to be able to act like it can change one, it should refer to a variable you create on your own which is initially assigned to the value of the configuration variable. See the ClariCGI configuration guide for a list of the standard configuration variables
All QueriesThe following variables are available during all queries. The provide the various parsed components of a query.
Hierarchy TemplatesFor the two hierarchy based templates, the variable template_hierarchy will contain the pathname of the directory at which the template was found. Of course, a template will usually know where it exists, but this allows more generic templates to be written that can be moved around from hierarchy to hierarchy.
Newsgroup Template
Sample Group TemplateThe following template is simlar to our default Newsgroup template. You will note that this template is called for both inline and menu queries, and such templates have to test query_artinline and act appropriately.
<body bgcolor=white> { title( Title ) } <h1 align=center>{Title}</h2> { clari_logo; query_header; } { # For inline queries, put a line before articles, otherwise start list if( query_artinline ) "<HR width=80% size=2 color=red>"; else %"<{List_Style}>"; fi # execute the query query( query_text ); %"</{List_Style}>" if !query_artinline; %"<P><a href={Script_Name}?;g:{query_newsgroup};l^{numberstag}>View all articles in {query_newsgroup}</a></P>" if Needs_Whole_Link; } Note the use of Needs_Whole_Link and numberstag to assure that the proper link to other stories is offered with the right query.
Menu of Newsgroups TemplateTwo templates are available here, to be defined in the configuration file. The master template controls the look of the entire page, and will contain a call to the list function usually with the query_newsgroup variable as an argument. The real control of individual elements comes from the special group_listing variable, which can be set in the master group_list template, or in general. Inside the group_listing template you can use the following:
Note that you can perform more complex matching if you simply have the pattern be something like a dot (.) to match all newsgroups, and have the test in the group_listing template, testing more complex regular expressions, or in fact doing anything the programming language can do to test newsgroups, including showing only groups with unread articles or groups that match one pattern but don't match another. Of course, you must make a new template for each complex pattern you want to evaluate.
Sample Groups Menu TemplatesHere is a simple template that makes a nice table for newsgroup menus, pulling descriptions from the DBM database. Here they are shown as they would be defined in the config file because that is normally where these would get defined.
Group List: {Title( "Newsgroup Menu: ", query_newsgroup )} <H1 align=center>Newsgroup Menu: {query_newsgroup}</H1> <CENTER><TABLE> {list( query_newsgroup, query_index );} </TABLE></center> Group Listing: <TR><TD align=right>{grouplist(List_Newsgroup);} <TD>{data("Short:" . List_Newsgroup);}</TR>
Article TemplateThese variables are available when doing output of an article. In addition, all headers from the USENET message are available with variable names equal to the header name in lower case, prefaced with "H_" and with non-alphanumeric characters mapped to underbar (_). For example the Message ID will be in the variable H_message_id, however you may prefer the variable Messageid which has the message-ID without angle brackets. Note that if a USENET header happens to match the name of a configuration file variable, it will not be set, since these variables may not be changed by user data or template programs. The following additional variables are defined:
Note that you can use the header() function to output a nice header. In fact, the default article layout can be coded as:
{ header(); body(); } But usually article templates like to manipulate the header a bit more than that.
Finding article templatesAn article template can be defined in the configuration file, or it can be defined by creating the file art.template in a newsgroup or hierarchy directory or overview directory. However, note that since most article references are made by message-id, the "current newsgroup" that is used to fetch the template may not be the newsgroup the user was reading. (A plan is underway to use browser cookies to assure that the group is right.)The group may end up being the first legal group in the news "history" file entry for the article's message-id. This means that per-group article templates may not currently work as planned unless you use article menus that refer to stories by group and article number instead of by message-id. (This is normally bad because you want the same message to always have the same URL, ie. the message-id, no matter what group the message is read from. If you have to include the newsgroup in the URL, you can't get that ability.) Article templates can of course be stored in the predefined templates directory, and applied to an article by specifying the template explicitly in the query with an "A:templatename" query operand.
Complex Article TemplateBelow you can see an article template that does pretty much what our default template does. You can modify this to your taste, adding or removing headers. Please note that ClariNet contractual requirements require that you display the copyright notice found in the Organization or Copyright header line of any ClariNet article, as well as the byline from the From: line and attribution to ClariNet at a minimum. Note this template has references to an image on our web server. You would of course modify this to point to an icon on your own server. Icons on our own servers are not guaranteed to be fixed or always present.
<HTML><BODY bgcolor=white> <IMG src="http://www.clari.net/Gifs/en-1inch.gif" width=72 height=20 align=right alt=""> { # Leader line if either a slugword or From: line if( H_slugword || H_from ) "<ADDRESS>"; %"<a href=http://www.clari.net/>ClariNet</a> Story <B>{H_slugword}</B> from " if slugword; %"<em>{H_from}</em> "; Provider; "</ADDRESS>"; fi } { Title( Title || "e.News: " . Subject ); } <H2 align=center>{ Title || Subject}</H2> { # We add the real subject as a sub-header if one was provided %"<h3 align=center>[{Subject}]</h3>" if Title;} <ADDRESS> {%"<STRONG>To:</STRONG> {H_to}<BR>" if H_to;} {%"<STRONG>CC:</STRONG> {H_cc}<BR>" if H_cc;} {%"<STRONG>{H_organization}</STRONG>" if H_organization;} {H_organization && H_date ? " / " # Insert delim if both are present } {H_date}<BR> {% "<STRONG>Keywords:</STRONG> {H_keywords}<BR>" if H_keywords;} {% "<STRONG>Summary:</STRONG> {H_summary}<BR>" if H_summary;} {% "<STRONG>Location:</STRONG> {H_location}<BR>" if H_location;} {% "Copyright {H_copyright}<BR>" if H_copyright;} </ADDRESS> {%"<STRONG>Priority:</STRONG> {H_priority}<BR>" if H_priority && H_priority != "regular";} {%"<STRONG>Format:</STRONG> {H_format}<BR>" if H_format;} {if( H_newsgroups ) "Newsgroups: "; grouplist( H_newsgroups ); "<BR>"; fi } {if( H_references ) "References: "; msgidlist( H_references ); "<BR>"; fi } <HR> {art_head} {body(0);} <HR><P>Thank you for using our system</P> Added at the end of the template is a tag line which is not present in the real default template
Headline Menu TemplateWhen a newsgroup displays a menu of headlines, there is actually a template for each menu entry. This allows you to make the entries and HTML list (the default) or an HTML table in just about any style you wish. You can also decide want to provide with each entry. You can actually modify this template. If you assign the list_member variable it is treated as a template for the display of headline menu items. The default template is as follows:
{List_Tag||"<LI>"} {"<img allign=top src=/Gifs/camera.gif>" if Art_Photo;} <a href="{Script_Name; if(query_usenumbers) %"?{query_newsgroup}:{Art_Number}"; else %"?;m:{Art_Message_ID};g^"; fi }">{"<font size=-1 color=darkgreen>[Seen]</font>" if Art_Seen; Art_Subject; }</a> - <font color=darkred><i>({fullname( Art_From )})</i></font> {%"<font size=-1 color=darkblue>{Art_Condate}</font>" if Art_Condate;} This outputs the List_Tag or <LI> if the tag is not set, then outputs a camera ICON if the article has graphics. Then it puts out a link to the article in either numeric or message-ID form, the link text being the headline. If the Art_Seen tag is set, it first puts out the word "Seen", small and in Green. It then outputs the full name of the author (byline) in dark red, and then the date in small size dark blue type if the date is not redundant. The following other variables are avilable in menu templates.
Table of ArticlesThe following template outputs a more table oriented menu of articles. You need to provide the starting and ending <TABLE> tags in the newsgroup template. You might assign such a string (escaping quotes and so on) to the variable List_Member. Here the various elements are input as table data segments inside a table row.
<TR> <TD> {"<img allign=top src=/Gifs/camera.gif>" if Art_Photo;} </TD> <TD><a href="{Script_Name; if(query_usenumbers) %"?{query_newsgroup}:{Art_Number}"; else %"?;m:{Art_Message_ID};g^"; fi }">{"<font size=-1 color=darkgreen>[Seen] %s</font>" if Art_Seen; Art_Subject;}</a> - <font color=darkred><i>({fullname( Art_From )})</i></font> </TD> <TD>{%"<font size=-1 color=darkblue>{Art_Condate}</font>" if Art_Condate;}</TD> </TR>
|
||
|