Monday, November 08, 2010 at 12:05 AM.

system.verbs.builtins.radio.webServer.setTemplate

on setTemplate (adratts, flHomePage, adrsite) {
	<<Changes:
		<<12/1/01; 2:44:07 PM by JES
			<<Don't use the desktopWebsiteTemplate for folderView pages.
		<<11/30/01; 9:15:08 PM by JES
			<<If this is the weblog editing page (a.k.a. home page), and flStaticRendering is false, then use the desktopWebsiteTemplate.
		<<11/30/01; 12:36:27 PM by JES
			<<Convert line-endings in templatetext to \r, before setting the template.
		<<11/28/01; 6:32:19 PM by DW
			<<Read the file instead of using the cached filetext.
		<<11/24/01; 5:21:45 PM by JES
			<<If pta^.flUseHeadTitle is defined and true, replace all of the <%title%> macros in the <head> section with <%homeTitle%> macros. Needed for setting the title in the title-bar on the prefs and help pages.
		<<10/29/01; 9:29:48 PM by PBS
			<<Put the <head> section into pta^.pageHeader, so that autoParagraphs, clayCompatibility, and activeUrls are not run in the <head> section. This fixes the bug with extraneous <p> tags, for example.
		<<10/17/01; 3:01:06 PM by PBS
			<<Set the template in the page table, not in the website itself, for thread-safety.
	local (pta = html.getPageTableAddress ());
	local (ftemplate = adratts^.template);
	if defined (adratts^.homeTemplate) {
		if flHomePage {
			ftemplate = adratts^.homeTemplate}};
	if defined (adratts^.desktopWebsiteTemplate) { //possibly use the desktopWebsiteTemplate
		if pta^.path == radio.data.systemUrls.weblogEditor {
			if not pta^.radioResponder.flStaticRendering {
				local (flFolderView = false);
				bundle { //set flFolderView
					if defined (pta^.radioResponder.postArgs.folderView) {
						if pta^.radioResponder.postArgs.folderView != "0" {
							flFolderView = true}};
					if file.isFolder (pta^.radioResponder.fileBeingRendered) {
						flFolderView = true}};
				if not flFolderView {
					ftemplate = adratts^.desktopWebsiteTemplate}}}};
	local (templatetext);
	bundle { //set templatetext for outlines
		local (adrcache);
		radio.file.getFileAttributes (ftemplate, @adrcache);
		case radio.webserver.getfilemimetype (ftemplate) {
			"text/x-opml" {
				templatetext = string (adrcache^.outline)}}
		else {
			templatetext = string (file.readwholefile (ftemplate))}};
	bundle { //convert line endings to \r
		templatetext = string.replaceAll (templatetext, "\r\n", "\r");
		templatetext = string.replaceAll (templatetext, "\n", "\r")};
	if date.versionLessThan (Frontier.version (), "7.1b1") { //patch macro delimiters
		templatetext = string.replaceAll (templatetext, adrsite^.["#prefs"].macroStartCharacters, "{", false);
		templatetext = string.replaceAll (templatetext, adrsite^.["#prefs"].macroEndCharacters, "}", false)};
	<<wp.newtextobject (templatetext, @adrsite^.["#template"])
	bundle { //PBS 10/29/01: separate into template and pageheader if possible
		local (ix = 0);
		ix = string.patternMatch ("<body ", string.lower (templatetext));
		if ix > 0 { //found <body> section?
			local (pageHeader = string.mid (templatetext, 1, ix - 1));
			if defined (pta^.flUseHeadTitle) {
				if pta^.flUseHeadTitle {
					pageHeader = string.replaceAll (pageHeader, "<%title%>", "<%headTitle%>", false)}};
			pta^.pageHeader = pageHeader;
			pta^.template = string.mid (templatetext, ix, infinity)}
		else { //couldn't find <body> section -- everything goes into pta^.template then
			pta^.template = templatetext}}; //PBS 10/17/01: template in page table, not in website itself
	return (true)}



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.