Application.cfc . , . Application.cfc onRequestStart() onRequestEnd(), . :
Application.cfc
component {
public function onRequest( required string targetPage ) {
savecontent variable='LOCAL.output' {
include ARGUMENTS.targetPage;
}
param string REQUEST.content = LOCAL.output;
include '/path/to/template.cfm';
}
}
template.cfm
<!DOCTYPE html>
<cfparam name="REQUEST.title" type="string" />
<cfparam name="REQUEST.head" type="string" default="" />
<cfparam name="REQUEST.content" type="string" />
<html>
<head>
<title><cfoutput>#REQUEST.title#</cfoutput></title>
<link rel="stylesheet" href="path/to/common.css" />
<script src="path/to/common.js"></script>
<cfoutput>#REQUEST.head#</cfoutput>
</head>
<body>
<header>...</header>
<cfoutput>#REQUEST.content#</cfoutput>
<footer>...</footer>
</body>
</html>
-page.cfm
<cfset REQUEST.title = "My Page Title" />
<cfsavecontent variable="REQUEST.head">
</cfsavecontent>
<p>Hello World</p>
, WYSIWYG. , , , .
And there is no need to create templates <cfinclude>on each page, since Application.cfc onRequest()will be called by default for ALL pages. If there are .cfm pages that should NOT include a design template, such as PDF output, then you will need to add some logic to simply unload the output and not include the design template.
source
share