ColdFusion開発者は、別のヘッダーとフッターファイルをインクルードすることを避けるために90年代後半にcf_bodycontentというカスタムタグを使用して開始しました。これは、ASP.NETのマスターページの6〜7年前です。 ;-)
同じことをするネイティブタグがあります:cfsavecontentです。テンプレートでcfsavecontentをどのように使用するかの本質は次のとおりです。
<!--- index.cfm --->
<cfsavecontent variable="content">
<cfinclude template="#url.action#.cfm">
</cfsavecontent>
<cfinclude template="template.cfm">
<!--- template.cfm --->
<cfparam name="title" default="Welcome">
<html>
<head><cfoutput>#title#</cfoutput></head>
<body>
... header, menu, sidebar, whatever ...
<cfoutput>#content#</cfoutput>
... right column, footer ...
</body>
</html>
<!--- foo.cfm --->
<cfset title="Welcome to Foo">
Hello World! I'm the page at index.cfm?action=foo
<!--- bar.cfm --->
<cfset title="Welcome to Bar">
Hello World! I'm the page at index.cfm?action=bar
テンプレート内にテンプレートを入れたい場合は、別のcfsavecontentを追加してください。
<!--- index.cfm --->
<cfsavecontent variable="content">
<cfinclude template="#url.action#.cfm">
</cfsavecontent>
<cfsavecontent variable="content">
<cfinclude template="internal_template.cfm">
</cfsavecontent>
<cfsavecontent variable="content">
<cfinclude template="master_template.cfm">
</cfsavecontent>
<cfoutput>#content#</cfoutput>
冗長性を削除するためにリファクタリングすることができます。
<!--- index.cfm --->
<cfsavecontent variable="content">
<cfinclude template="#url.action#.cfm">
</cfsavecontent>
<cfparam name="templates" default="internal,master">
<cfloop list="#templates#" index="t">
<cfsavecontent variable="content">
<cfinclude template="#t#_template.cfm">
</cfsavecontent>
</cfloop>
<cfoutput>#content#</cfoutput>
使用すると、1つのテンプレート別の「拡張」を持っているしたい場合は、多分スタックにリストを回して、各テンプレートは、スタックにその親を押すことによってそれを行うことができます。
<!--- internal_template.cfm --->
<cfset templates = listAppend("master", templates)>
...
<cfoutput>#content#</cfoutput>
...
<!--- index.cfm --->
<cfsavecontent variable="content">
<cfinclude template="#url.action#.cfm">
</cfsavecontent>
<cfparam name="templates" default="internal">
<cfloop condition="listlen(templates) gt 0">
<cfset t = listFirst(templates)>
<cfset templates = listRest(templates)>
<cfsavecontent variable="content">
<cfinclude template="#t#_template.cfm">
</cfsavecontent>
</cfloop>
<cfoutput>#content#</cfoutput>
StackOverflowで考案されたColdFusionフレームワークであるStackBoxがあります。 :-)
ハ、私はそれを投稿したことに気づく前に、この質問を読んでください。ネットがありませんか? –