Synchronet v3.19b-Win32 (install) has been released (Jan-2022).

You can donate to the Synchronet project using PayPal.

This is an old revision of the document!


Web Server SSJS Template System

The default web pages use a SSJS Template engine which also allows for Theme support.

[Note: With this latest implementation of SSJS, @@ codes no longer can be nested.]

The SSJS Template Scheme

Each page consists of four parts:

The Header

../web/templates/default/header.inc  

This file contains the basic requirements for the HTML page. The opening HTML, doctype, title, CSS file link, etc. The header file includes the open body, System Name, and User greeting plus the initial page layout table start. The rest of the layout is continued in the next files.

Top Navigation

../web/templates/default/topnav.inc
../web/lib/topnav_html.ssjs

The topnav.inc file contains the basic design of the “breadcrumbs” The links are dynamically generated by topnav_html.ssjs so both files need to be addressed when modifying or creating themes. In the case of the default layout, topnav.inc has a left and right graphic and a middle section that the dynamic content goes. The background image is handled by CSS. You can change this to anything you like.

The topnav_html.ssjs file may seem daunting at first, but it is pretty straight forward. It has a series of if statements that check the current page location and sets up the breadcrumbs based on what you want it to say.

For example: You want to add a Links page called links.html in the main directory. You would add a check for the path to links.html as:

if(http_request.virtual_path=="/links.html")
    template.topnav.push({html: '<span class="tlink">Some Links</span>'});

Left Side Navigation

../web/templates/default/leftnav.inc
../web/lib/leftnav_nodelist.ssjs
../web/lib/leftnav_html.ssjs

This starts the main table layout in the default layout and also provides two other things – the main navigation links and a brief nodelisting that displays when users are online via telnet. The links are dynamically created as in the Top Navigation example above with the exception of the two static links.

Main Content (various files)

This is where the layout of the main content is created. It is best to look at the various files in ../web/templates/default & ../web/templates/default/msgs to see how the code is displayed for the various functions of the Web side of Synchronet. Some details on what each of the special codes contained in those files do will follow.

Fооter

../web/templates/default/footer.inc

This file contains the closing HTML and whatever bottom information you would like. In the case of the default layout, the Web Server/Synchronet versions and the XHTML 1.0 logo. Links to privacy statements or anything else can be placed here and they will be displayed at the bottom of each page.

Custom .inc

To Add a custom link to the left side navigation list using the nightshade theme edit ../web/lib/nightshade/leftnav_html.ssjs and add the link to the list.
note: the link expects an html tag “<li><a href=“some-script.ssjs”>My Link</a></li>”

template.leftnav.push({html: '<li><a href="/members/externals.ssjs">External Programs</a></li><li><a href="/bbs/bbses.ssjs">BBS Links</a></li><li><a href="/members/lastcallers.ssjs">Last Callers</a></li><li><a href="/members/info.ssjs">Information</a></li><li><a href="/members/newpw.ssjs">Change Password</a></li><li><a href="/logout.ssjs">Logout</a></li><li><a href="/msgs/msgs.ssjs?msg_sub=mail">E-mail</a></li>' });  

Here we added the link BBS Links to the left side navigation that points to bbses.ssjs. Now create the script called ../web/root/bbs/bbses.ssjs

load("../web/lib/template.ssjs");
 
template.title= system.name + " - BBS Connect";
 
template.whatever = "<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Some kind of stuff will go here, eventually!"
 
var sub = ''; /* Do not delete/change this */
 
/* below values are set in ../web/lib/html_themes.ssjs  */
if(do_header) 
	write_template("header.inc");
if(do_topnav)
	load(topnav_html);
if(do_leftnav)
load(leftnav_html);
 
if(do_rightnav)
	write_template("rightnav.inc");
 
write_template("bbses.inc");
 
if(do_footer)
	write_template("footer.inc");

Now you need a corresponding ../web/root/templates/nightshade/bbbes.inc

<!-- $Id: bbses.inc,v 0.1 2021/02/18 02:19:55 lamer Exp $ -->
 
<!-- Begin BBS Connect Content -->
 
@@whatever@@		
 
<!-- End Main Content -->

SSJS Theme Support

Theme Layouts can be added to Synchronet by creating them and placing the *.inc files in their own directory under ../web/templates/

Themes are activated by editing the ../web/templates/html_themes.ssjs file. This file contains:

/* Set default theme name */
var DefaultTheme="Default";
 
/* Edit this bit to add/remove/modify theme descriptions and dirs */
Themes["Default"]=new Object;
Themes["Default"].desc="Default Synchronet Theme";
Themes["Default"].dir="default";
Themes["Default"].css="/synchronet.css"; 

Themes are added by editing below the Default Theme such as:

Themes["CoolTheme"]=new Object;
Themes["CoolTheme"].desc="My Cool Theme";
Themes["CoolTheme"].dir="cooltheme";
Themes["CoolTheme"].css="/cooltheme.css";

To change the Default Theme, change:

var DefaultTheme="Default";

to:

var DefaultTheme="CoolTheme";

Special Codes Used in the SSJS Template System

By looking at at the message related files located in templates/default/msgs, it can be seen that some special codes are used to display dynamically created content. It is very important to maintain the information EXACTLY as seen in each file or else the messaging system will fail. While how it is displayed can be changed, the correct information will only be dispayed by following the format in the *.inc files.

For example the groups.inc:

<!-- Main Content -->  
 
<td class="main" valign="top"><br />
 
<table class="grouplist" border="0" cellpadding="2" cellspacing="2">
<tr>
<th class="grouplist">Message Group</th><th class="grouplist">Subs</th>
</tr>
<<REPEAT groups>>
<tr>
  <td class="grouplist">
      <a class="grouplist" href="subs.ssjs?msg_grp=^^groups:name^^">
          %%groups:description%%</a></td>
  <td class="grouplist" align="right">
      @@JS:msg_area.grp_list[RepeatObj.index].sub_list.length@@</td>
</tr>
<<END REPEAT groups>>
</table>
<br />
 
<!-- end Main Content -->

While the table layout can be changed or even eliminated, the information within the «REPEAT groups>> and «END REPEAT groups>> must remain intact. To remove the table yet keep the correct infomation, the resulting groups.inc would be changed to (while maintaining the main table layout in this case) to:

<!-- Main Content -->  
 
    <td class="main" valign="top"><br />
 
  <<REPEAT groups>>
    <a class="grouplist" href="subs.ssjs?msg_grp=^^groups:name^^">
        %%groups:description%%</a>
    @@JS:msg_area.grp_list[RepeatObj.index].sub_list.length@@<br />
  <<END REPEAT groups>>
 
  <br />
 
  <!-- end Main Content -->

This principle applies to all the .inc files in msgs respectively.

The SSJS Template Library

name is replaced with the HTML encoded value of template.name

i.e.; Spaces are replaced with: this&nbsp;is&nbsp;html

^^name^^ is replaced with the URI encoded value of template.name

i.e.; Spaces are replaced with: this%20is%20URI

@@name@@ is replaced with the value if template.name

No changes or encoding is performed.

@@name:sname@@ is replaced with the value of template.name.sname (^^ and are also supported) ''@@JS:js_expression@@'' is replaced with the return value of ''js_expression'' (^^ and are also supported)

<<REPEAT name>>
  @@name:sname@@
<<END REPEAT name>>

Iterates over the array/object template.name and replaces name:sname with the value of template.name.sname. (^^ and %% are also supported)

SSJS Message Configuration

Configuration settings for the SSJS Messaging system is located in the ../web/lib/msgsconfig.ssjs file:

max_messages=20;
max_pages=30;
next_msg_html="Next Message";
prev_msg_html="Previous Message";
next_page_html="NEXT";
prev_page_html="PREV";
showall_subs_enable_html="Show all subs";
showall_subs_disable_html="Show subs in new scan only";
show_messages_all_html="Show all messages";
show_messages_yours_html="Show messages to you only";
show_messages_your_unread_html="Show unread messages to you only";
show_messages_spacer_html="&nbsp;<b>|</b>&nbsp;";
anon_only_message="Message will be posted anonymously";
anon_allowed_message='<input type="checkbox" name="anonymous" value="Yes" /> Post message anonymously';
anon_reply_message='<input type="checkbox" name="anonymous" value="Yes" checked /> Post message anonymously';
private_only_message="Message will be marked private";
private_allowed_message='<input type="checkbox" name="private" value="Yes" /> Mark message as private';
private_reply_message='<input type="checkbox" name="private" value="Yes" checked /> Mark message as private';

Each of these are configurable.

See the actual file for the defaults currently in use.

Embedded Javascript

The *.inc files can (and do in the default layout) have embedded JavaScript which is parsed by the JavaScript engine. Care should be taken as a large number of embedded JavaScript in the *.inc files slow down overall processing of pages.

Anything contained within @@JS: @@ is processed by the Server-side JavaScript engine.

For example, it can check if the user is Guest or an actual user with this line:

@@JS:if(user.number==0 || user.security.restrictions&UFLAG_G) '<html code for Guest>'; \
else '<html code for registered user>';@@

What this does is display links specific for Registered Users only to them and not Guest. There are many things that can be done with @@JS: @@ code. Note, it also can be used to display HTML based on location as in the node listing stuff. In this case, it checks for whether or not a user is online, or if the user is anywhere but the Who's Online page before displaying the Left side node listing.

IMPORTANT! Anything contained within @@JS: @@ MUST be on one line or there will be errors in parsing.

global_defs.ssjs

This version of the Web Layout now includes a new file called global_defs.ssjs. It is located in the ../web/lib directory. This file can be used for creating global definitions that span all pages of a site. For example:

template.user_alias=user.alias;

Now @@user_alias@@ can be in any *.inc template files and it will display the user's alias.

Care should be exercised when using this file as loading it up with hundreds of predefined definitions may slow down overall page rendering as the file is loaded on every page. It would be better to just put a few popular definitions that are truly global rather many definitions. It would be inefficient to have thirty of forty message definitions being loaded when a user is looking at the statistics page.

See Also