Does ColdFusion get response to the main ASP.NET pages?

I am working on a site that has been encoded in ColdFusion. I have a CSS / HTML template that I would like to apply to the content of each page without duplicating more code than necessary. I am a little spoiled by ASP.NET master pages, which would be my preferred way to implement this site. Unfortunately, this option is not available to me. This site should run on Coldfusion MX 7. In addition, the project manager does not like Fusebox, so the option is disabled.

The main navigation, graphic title and footer will be the same on every page. The title tag, meta tags, and level 2 navigation system are likely to change from page to page. Other than that, only the "main content area" page will be different.

Given these parameters, how can I encode a site for maximum maintainability?

+7
coldfusion design-patterns master-pages code-reuse
source share
4 answers

There are many ways to do this with ColdFusion.


Application.cfc is executed for each request and has two methods ( onRequestStart and onRequestEnd ) that can be used to add / add content to the main script on the page.

It's also worth noting that it is possible to extend / inherit your Application.cfc, allowing a more complex set of RequestStart / End events. More details here and here .


Custom tags allow you to create a tag that you can wrap around each template to apply the / etc layout. It also allows the / etc attributes to define generic but changing text.

For example:

 <cf_page PageTitle="My Page"> [main page content] </cf_page> 

And inside the user tag (page.cfm) you have:

 <cfif ThisTag.ExecutionMode EQ 'start'> <cfparam name="Attributes.PageTitle" default=""/> <cfcontent reset/><cfoutput><!DOCTYPE html> <html> <head> <title>My Website - #Attributes.PageTitle</title> [styles and scripts and stuff] </head> <body> <div id="heading"> <img src="my_website_logo.png" alt="My Website"/> </div> <ul id="mainmenu" class="nav"> [menu] </ul> <h1>#Attribute.PageTitle#</h1> </cfoutput> <cfelse> <cfoutput> <div id="footer"> [footer] </div> </body></html></cfoutput> </cfif> 

And, of course, you can create several custom tags or one tag that works differently depending on the specified attributes.


Henry already mentioned MVC Frameworks , but you do not need to do MVC to use the functionality of templates / layouts.

Fusebox can run MVC, but it doesnโ€™t require you to do this, and in any case, FB ContentVariables is a good tool for implementing modular content - unless your lead developer can justify your dislike of Fusebox (and suggest an alternative that suits your project!), There is absolutely no reason not to go for it - this is a mature and well-known structure, easy to use, many developers, etc.

However, if Fusebox is really not an option, look at the list of Charlie Areart frameworks - this page as a whole is a huge list of tools that are worth paying attention to.


Anyway, this should give you enough things to consider at the moment ...

+12
source share

ColdFusion developers started using the special cf_bodycontent tag in the late 90s to avoid including separate header and footer files. That was six or seven years before the ASP.NET Master Pages .; -)

Now there is a custom tag that does the same: cfsavecontent . Here's the gist of how people use cfsavecontent in templates.

  <!--- 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 

If you want to put the template in the template, just add another 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> 

You can reorganize to cut redundancy.

  <!--- 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> 

If you want one template to โ€œextendโ€ the other, you could do this by turning the list onto the stack, and each template pops its parent onto the stack.

  <!--- 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> 

So you have StackBox, the ColdFusion framework built on StackOverflow. :-)

+3
source share

You can try one of the MVC frameworks with template support (almost everyone has one).

ColdBox , Model-Glue , Mach-II , Fusebox ...

This Galleon Ports Comparings Comparings page shows how each structure handles templates ...

+1
source share

check CFINCLUDE

0
source share

All Articles