130 likes | 316 Views
Server-side includes. Library and Information Services University of St Andrews. What are server-side includes (SSI)?. Mechanism of employing the web server to perform certain tasks displaying files as part of other files displaying information dynamically (dates, URLs) Server support needed.
E N D
Server-side includes Library and Information Services University of St Andrews
What are server-side includes (SSI)? • Mechanism of employing the web server to perform certain tasks • displaying files as part of other files • displaying information dynamically (dates, URLs) • Server support needed
File extensions: .html .shtml • Files containing SSI are html files • Server only parses files with extension .shtml for SSI • Rename/save any files that contain SSI directives as .shtml
SSI directives • Code inserted into html source of a document • Syntax: • <!--#element attribute=“value” --> • <!--#element attribute1=“value1” attribute2=“value2” --> • Various elements (e.g. “include”, “echo”, “config”) and attributes to go with these elements
SSI elements: include • Syntax: <!--#include virtual=“path/file.html” --> • Inserts a file into another file • Including file: file that contains the SSI directive • Included file: file that is displayed as part of another file
<html> <head> <title>SSI demo</title> </head> <body> <h1>SSI demo</h1> <p>Some text …</p> <!--#include virtual=“file.html” --> <p>some more text …</p> </body> </html> <!-- *** file.html *** vis SSI --> <p>School of Pottery <br />University of St Andrews <br />St Andrews <br />Fife <br />KY16 9AJ</p> <p>Email: <a href=“mailto:pottery@st-andrews.ac.uk>pottery@st-andrews.ac.uk</a> </p> <!-- *** End of file.html *** --> Including and included files Including file Included file
Including and included file <html> <head> <title>SSI demo</title> </head> <body> <h1>SSI demo</h1> <p>Some text …</p> <!-- *** file.html *** vis SSI --> <p>School of Pottery <br />University of St Andrews <br />St Andrews <br />Fife <br />KY16 9AJ</p> <p>Email: <a href=“mailto:pottery@st-andrews.ac.uk>pottery@st-andrews.ac.uk</a></p> <!-- *** End of file.html *** --> <p>some more text …</p> </body> </html>
SSI elements: echo • Displaying URLs dynamically • Syntax: <!--#echo var=“HTTP_HOST” var=“DOCUMENT_URI” --> • Displaying last modified date dynamically • Sxntax: <!--#echo var=“LAST_MODIFIED” --> • Displaying date and time dynamically • Syntax: <!--#echo var=“DATE_LOCAL” -->
SSI elements: config • Configure current and last modified time stamps • Syntax: <!--#config timefmt=“%A, %d %B %Y” --> Directiveappears immediately in front directive for time stamp <!--#config timefmt=“%A, %d %B %Y” --> <--#echo var=“DATE_LOCAL” --> will display e.g. Wednesday, 12 November 2003
Timefmt: values • Server dependent • Some values that can be used in St Andrews: %a Abbreviated day name %A Full day name %d Day as number (1-31) %b Abbreviated month name %B Full month name %m Month as number (1-12) %H Hour as number (24-hour clock) %I Hour as number (12-hour clock) %M Minute as number (00-59) %S Second as number (00-59) %Y Year
Why use SSI? • For templates: • to ensure consistent layout • Content management on institutional web sites • Control privileges of various web masters • Avoiding unnecessary duplication of repetitive content • Ease of updating • Time management