fro*_*die 5 coldfusion logic templates master-pages
我的网站有一个小的coldfusion部分,它们都使用类似的js和css文件和页面结构.目前,每个文件都重复使用该代码,我想将其考虑在内并使用母版页和模板进行设置.
Master.cfm页面:
<!--- Master template, includes all necessary js and css files.
Expects following variables to be defined:
- pageName - name of the file to be loaded as the body of the page
- title - text to be used as the title of the page and as the header text in the header bar --->
<cfinclude template="_lockedPage.cfm" />
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>#title#</title>
... all script and css links here ...
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.3.2.js"></script>
... etc ...
</head>
<body>
<div data-role="page">
<div class="headerDiv" data-role="header" data-theme="b" data-position="fixed">
<a id="backButton" data-role="button" data-direction="reverse" data-rel="back" data-icon="arrow-l" data-iconpos="left" data-theme="a">Back</a>
<h1><cfoutput>#title#</cfoutput></h1>
<a href="index.cfm" data-role="button" data-icon="home" data-iconpos="left" data-theme="a">Home</a>
</div>
<div data-role="content" class="container">
<cfinclude template="#pageName#.cfm" />
</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
然后页面示例将是这样的.CustomerSearch.cfm:
<cfscript>
title = "Customer Search";
pageName = "_customer-search";
include "Master.cfm";
</cfscript>
Run Code Online (Sandbox Code Playgroud)
然后我需要一个_customer-search.cfm页面,其中包含页面的所有正文内容.
这意味着我需要为我们当前拥有的每个页面提供2个文件 - 定义变量的外部页面,包括主页面,以及具有单独页面内容的模板页面.
这是一个很好的逻辑结构吗?反正有改进吗?
你有正确的想法,但我认为你最终会得到很多不必要的文件.您可以改为创建包含全局HTML的a header.cfm和a footer.cfm.每个页面都包含这些文件,内容将在其间写入.
<cfset title = "Customer Search">
<cfinclude template="global_header.cfm">
<!--- This will be the content of your page. --->
<cfinclude template="global_footer.cfm">Run Code Online (Sandbox Code Playgroud)
该文件将被命名customer_search.cfm.无论何时更新页眉或页脚,都是全局变化.
如果您有许多需要存在于多个页面上的业务逻辑和查询代码,您可能会考虑使用MVC框架来帮助您组织和重用代码.我更喜欢ColdBox(尝试ColdBox Lite),但很多人使用Framework/1.